zshrc: do not fall back to LANG en_US.iso885915 if it is unset
[grml-etc-core.git] / etc / zsh / zshrc
index 32f3831..7773ed9 100644 (file)
@@ -230,6 +230,8 @@ zrcautoload is-at-least || is-at-least() { return 1 }
 NOCOR=${NOCOR:-0}
 NOMENU=${NOMENU:-0}
 NOPRECMD=${NOPRECMD:-0}
+COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
+GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
 BATTERY=${BATTERY:-0}
 GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
 GRML_ALWAYS_LOAD_ALL=${GRML_ALWAYS_LOAD_ALL:-0}
@@ -446,6 +448,7 @@ xunfunction() {
 # this allows us to stay in sync with grml's zshrc and put own
 # modifications in ~/.zshrc.local
 zrclocal() {
+    xsource "/etc/zsh/zshrc.local"
     xsource "${HOME}/.zshrc.local"
     return 0
 }
@@ -453,12 +456,9 @@ zrclocal() {
 #}}}
 
 # locale setup {{{
-if [[ -z "$LANG" ]] ; then
-   xsource "/etc/default/locale"
-fi
+xsource "/etc/default/locale"
 
-export LANG=${LANG:-en_US.iso885915}
-for var in LC_ALL LC_MESSAGES ; do
+for var in LANG LC_ALL LC_MESSAGES ; do
     [[ -n ${(P)var} ]] && export $var
 done
 
@@ -630,6 +630,14 @@ grml_toggle_abbrev() {
 zle -N grml_toggle_abbrev
 bindkey '^xA' grml_toggle_abbrev
 
+# add a command line to the shells history without executing it
+commit-to-history() {
+    print -s ${(z)BUFFER}
+    zle send-break
+}
+zle -N commit-to-history
+bindkey "^x^h" commit-to-history
+
 # }}}
 
 # a generic accept-line wrapper {{{
@@ -1619,10 +1627,17 @@ VCS_INFO_git_get_data () { # {{{
 }
 # }}}
 VCS_INFO_hg_get_data () { # {{{
-    local hgbranch hgbase
+    local hgbranch hgbase file
 
     hgbase=${vcs_comm[basedir]}
-    hgbranch=$(< ${hgbase}/.hg/branch)
+
+    file="${hgbase}/.hg/branch"
+    if [[ -r ${file} ]] ; then
+        hgbranch=$(< ${file})
+    else
+        hgbranch='default'
+    fi
+
     VCS_INFO_formats '' "${hgbranch}" "${hgbase}"
     return 0
 }
@@ -1683,7 +1698,7 @@ VCS_INFO_detect_by_dir() { #{{{
     while [[ ${realbasedir} != '/' ]]; do
         if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
             [[ -d ${basedir}/${dirname} ]] && \
-            [[ -f ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
+            [[ -e ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
                 break
         else
             [[ -d ${basedir}/${dirname} ]] && break
@@ -1737,7 +1752,7 @@ VCS_INFO_git_detect() { #{{{
 # }}}
 VCS_INFO_hg_detect() { #{{{
     VCS_INFO_check_com hg || return 1
-    vcs_comm[detect_need_file]=branch
+    vcs_comm[detect_need_file]=store
     VCS_INFO_detect_by_dir '.hg'
     return $?
 }
@@ -1907,6 +1922,19 @@ fi
 
 # }}}
 
+# command not found handling {{{
+
+(( ${COMMAND_NOT_FOUND} == 1 )) &&
+function command_not_found_handler() {
+    setopt localoptions no_sh_wordsplit
+    if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
+        ${GRML_ZSH_CNF_HANDLER} $1
+    fi
+    return 1
+}
+
+# }}}
+
 # {{{ set prompt
 if zrcautoload promptinit && promptinit 2>/dev/null ; then
     promptinit # people should be able to use their favourite prompt
@@ -1971,7 +1999,7 @@ preexec () {
 # adjust title of xterm
     [[ ${NOTITLE} -gt 0 ]] && return 0
     case $TERM in
-        (xterm*|rxvt)
+        (xterm*|rxvt*)
             print -Pn "\e]0;%n@%m: $1\a"
             ;;
     esac
@@ -2195,6 +2223,11 @@ the zsh yet. :)
   "NOTITLE=1  zsh" => disable setting the title of xterms without disabling
                       preexec() and precmd() completely
   "BATTERY=1  zsh" => activate battery status (via acpi) on right side of prompt
+  "COMMAND_NOT_FOUND=1 zsh"
+                   => Enable a handler if an external command was not found
+                      The command called in the handler can be altered by setting
+                      the GRML_ZSH_CNF_HANDLER variable, the default is:
+                      "/usr/share/command-not-found/command-not-found"
 
 A value greater than 0 is enables a feature; a value equal to zero
 disables it. If you like one or the other of these settings, you can
@@ -2257,9 +2290,9 @@ if [[ -r /etc/debian_version ]] ; then
      fi
 
     #a1# Take a look at the syslog: \kbd{\$PAGER /var/log/syslog}
-    alias llog="$PAGER /var/log/syslog"     # take a look at the syslog
+    salias llog="$PAGER /var/log/syslog"     # take a look at the syslog
     #a1# Take a look at the syslog: \kbd{tail -f /var/log/syslog}
-    alias tlog="tail -f /var/log/syslog"    # follow the syslog
+    salias tlog="tail -f /var/log/syslog"    # follow the syslog
 fi
 
 # sort installed Debian-packages by size
@@ -2465,7 +2498,9 @@ grmlcomp() {
 
     # use generic completion system for programs not yet defined; (_gnu_generic works
     # with commands that provide a --help option with "standard" gnu-like output.)
-    compdef _gnu_generic tail head feh cp mv df stow uname ipacsum fetchipac
+    for compcom in tail head feh cp mv df stow uname ipacsum fetchipac; do
+        [[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
+    done; unset compcom
 
     # see upgrade function in this file
     compdef _hosts upgrade
@@ -2846,6 +2881,17 @@ minimal-shell() {
     exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh
 }
 
+# a wrapper for vim, that deals with title setting
+#   VIM_OPTIONS
+#       set this array to a set of options to vim you always want
+#       to have set when calling vim (in .zshrc.local), like:
+#           VIM_OPTIONS=( -p )
+#       This will cause vim to send every file given on the
+#       commandline to be send to it's own tab (needs vim7).
+vim() {
+    VIM_PLEASE_SET_TITLE='yes' command vim ${VIM_OPTIONS} "$@"
+}
+
 # make a backup of a file
 bk() {
     cp -a "$1" "${1}_$(date --iso-8601=seconds)"
@@ -2914,10 +2960,6 @@ exit 0;
 for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; unset $color
 # }}}
 
-# source another config file if present {{{
-xsource "/etc/zsh/zshrc.local"
-# }}}
-
 # "persistent history" {{{
 # just write important commands you always need to ~/.important_commands
 if [[ -r ~/.important_commands ]] ; then
@@ -2986,11 +3028,6 @@ alias CO="./configure"
 #a2# Execute \kbd{./configure --help}
 alias CH="./configure --help"
 
-# http://conkeror.mozdev.org/
-# TODO: I think this should be removed, as conkeror is not a simple extension anymore
-#a2# Run a keyboard driven firefox
-alias conkeror='firefox -chrome chrome://conkeror/content'
-
 # arch/tla stuff
 if check_com -c tla ; then
     #a2# Execute \kbd{tla what-changed --diffs | less}