zshrc: check for DIRSTACK{SIZE,FILE} in chpwd()
[grml-etc-core.git] / etc / zsh / zshrc
index e475070..1af7ed7 100644 (file)
@@ -521,10 +521,6 @@ for var in LANG LC_ALL LC_MESSAGES ; do
     [[ -n ${(P)var} ]] && export $var
 done
 
-xsource "/etc/sysconfig/keyboard"
-
-TZ=$(xcat /etc/timezone)
-
 # set some variables
 if check_com -c vim ; then
 #v#
@@ -992,11 +988,10 @@ zle -N accept-line
 zle -N Accept-Line
 zle -N Accept-Line-HandleContext
 
-# power completion - abbreviation expansion
 # power completion / abbreviation expansion / buffer expansion
 # see http://zshwiki.org/home/examples/zleiab for details
 # less risky than the global aliases but powerful as well
-# just type the abbreviation key and afterwards ',.' to expand it
+# just type the abbreviation key and afterwards 'ctrl-x .' to expand it
 declare -A abk
 setopt extendedglob
 setopt interactivecomments
@@ -1195,10 +1190,10 @@ help_zle_parse_keybindings()
             if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
                 lastkeybind_desc="$match[*]"
                 num_lines_elapsed=0
-            #zsh pattern: matches lines that set a keybinding using bindkey or compdef -k
+            #zsh pattern: matches lines that set a keybinding using bind2map, bindkey or compdef -k
             #             ignores lines that are commentend out
             #             grabs first in '' or "" enclosed string with length between 1 and 6 characters
-            elif [[ "$cline" == [^#]#(bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*)  ]]; then
+            elif [[ "$cline" == [^#]#(bind2maps[[:space:]](*)-s|bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*)  ]]; then
                 #description prevously found ? description not more than 2 lines away ? keybinding not empty ?
                 if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
                     #substitute keybinding string with something readable
@@ -1342,9 +1337,11 @@ function bind2maps () {
 
 if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
     function zle-smkx () {
+        emulate -L zsh
         printf '%s' ${terminfo[smkx]}
     }
     function zle-rmkx () {
+        emulate -L zsh
         printf '%s' ${terminfo[rmkx]}
     }
     function zle-line-init () {
@@ -1406,7 +1403,7 @@ bind2maps emacs             -- Right  forward-char
 bind2maps       viins vicmd -- Right  vi-forward-char
 bind2maps       viins vicmd -- Right  vi-forward-char
 #k# Display list of abbreviations that expand when followed by ,.
-bind2maps emacs viins       -- -s ',.' zleiab
+bind2maps emacs viins       -- -s '^x.' zleiab
 bind2maps emacs viins       -- -s '^xb' help-show-abk
 bind2maps emacs viins       -- -s '^xM' inplaceMkDirs
 #k# display help for keybindings and ZLE
@@ -1559,6 +1556,7 @@ if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
 fi
 
 chpwd() {
+    if (( $DIRSTACKSIZE <= 0 )) || [[ -z $DIRSTACKFILE ]]; then return; fi
     local -ax my_stack
     my_stack=( ${PWD} ${dirstack} )
     if is42 ; then
@@ -1853,7 +1851,7 @@ grml_prompt_pre_default=(
     newline           ''
     path              '%B'
     percent           ''
-    rc                '%F{red}'
+    rc                '%B%F{red}'
     rc-always         ''
     sad-smiley        ''
     shell-level       '%F{red}'
@@ -1874,7 +1872,7 @@ grml_prompt_post_default=(
     newline           ''
     path              '%b'
     percent           ''
-    rc                '%f'
+    rc                '%f%b'
     rc-always         ''
     sad-smiley        ''
     shell-level       '%f'
@@ -1904,6 +1902,14 @@ grml_prompt_token_default=(
     vcs               '0'
 )
 
+function grml_theme_has_token () {
+    if (( ARGC != 1 )); then
+        printf 'usage: grml_theme_has_token <name>\n'
+        return 1
+    fi
+    (( ${+grml_prompt_token_default[$1]} ))
+}
+
 function GRML_theme_add_token_usage () {
     cat <<__EOF__
   Usage: grml_theme_add_token <name> [-f|-i] <token/function> [<pre> <post>]
@@ -1925,6 +1931,11 @@ function GRML_theme_add_token_usage () {
     return value is expected in the \$REPLY parameter. The use of these
     options is mutually exclusive.
 
+    There is a utility function \`grml_theme_has_token', which you can use
+    to test if a token exists before trying to add it. This can be a guard
+    for situations in which a \`grml_theme_add_token' call may happen more
+    than once.
+
   Example:
 
     To add a new token \`day' that expands to the current weekday in the
@@ -1988,7 +1999,7 @@ grml_theme_add_token: <pre> and <post> need to by specified _both_!\n\n'
         shift 2
     fi
 
-    if (( ${+grml_prompt_token_default[$name]} )); then
+    if grml_theme_has_token $name; then
         printf '
 grml_theme_add_token: Token `%s'\'' exists! Giving up!\n\n' $name
         GRML_theme_add_token_usage
@@ -2033,7 +2044,7 @@ function grml_prompt_addto () {
     for it in "${items[@]}"; do
         zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" pre apre \
             || apre=${grml_prompt_pre_default[$it]}
-        zstyle -s ":prompt:grml:${grmltheme}:${lr}:$it" post apost \
+        zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" post apost \
             || apost=${grml_prompt_post_default[$it]}
         zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" token new \
             || new=${grml_prompt_token_default[$it]}
@@ -2157,7 +2168,7 @@ if is437; then
         unset i
         zstyle ':prompt:grml(|-large|-chroot):right:setup' use-rprompt false
     elif (( EUID == 0 )); then
-        zstyle ':prompt:grml(|-large|-chroot):*:items:user' pre '%F{red}'
+        zstyle ':prompt:grml(|-large|-chroot):*:items:user' pre '%B%F{red}'
     fi
 
     # Finally enable one of the prompts.
@@ -2281,8 +2292,8 @@ fi
 
 # do we have GNU ls with color-support?
 if [[ "$TERM" != dumb ]]; then
-    #a1# List files with colors (\kbd{ls -b -CF \ldots})
-    alias ls='ls -b -CF '${ls_options:+"${ls_options[*]}"}
+    #a1# List files with colors (\kbd{ls -CF \ldots})
+    alias ls='ls -CF '${ls_options:+"${ls_options[*]}"}
     #a1# List all files, with colors (\kbd{ls -la \ldots})
     alias la='ls -la '${ls_options:+"${ls_options[*]}"}
     #a1# List files with long colored list, without dotfiles (\kbd{ls -l \ldots})
@@ -2292,7 +2303,7 @@ if [[ "$TERM" != dumb ]]; then
     #a1# List files with long colored list, append qualifier to filenames (\kbd{ls -lF \ldots})\\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
     alias l='ls -lF '${ls_options:+"${ls_options[*]}"}
 else
-    alias ls='ls -b -CF'
+    alias ls='ls -CF'
     alias la='ls -la'
     alias ll='ls -l'
     alias lh='ls -hAl'