X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=30f15504135ce42eb48bc9b2e02a1f616a035c22;hp=58ff6a613a8f664e2f81f4953e835d29bfd734c1;hb=b2a42cb947f2a21a42fe2650a47f7d36e3762d59;hpb=8d787e599d8385301c13c98b37da4f28764c1d5c diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 58ff6a6..30f1550 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -332,6 +332,17 @@ BATTERY=${BATTERY:-0} GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1} ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0} +typeset -ga ls_options +typeset -ga grep_options +if ls --help 2> /dev/null | grep -q GNU; then + ls_options=( --color=auto ) +elif [[ $OSTYPE == freebsd* ]]; then + ls_options=( -G ) +fi +if grep --help 2> /dev/null | grep -q GNU; then + grep_options=( --color=auto ) +fi + # utility functions # this function checks if a command exists and returns either true # or false. This avoids using 'which' and 'whence', which will @@ -660,8 +671,8 @@ bindkey "\e[5~" history-beginning-search-backward-end # PageUp #k# search history forward for entry beginning with typed text bindkey "\e[6~" history-beginning-search-forward-end # PageDown -# bindkey -s '^L' "|less\n" # ctrl-L pipes to less -# bindkey -s '^B' " &\n" # ctrl-B runs it in the background +# bindkey -s '^l' "|less\n" # ctrl-L pipes to less +# bindkey -s '^b' " &\n" # ctrl-B runs it in the background # insert unicode character # usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an ยง @@ -669,7 +680,7 @@ bindkey "\e[6~" history-beginning-search-forward-end # PageDown zrcautoload insert-unicode-char zle -N insert-unicode-char #k# Insert Unicode character -bindkey '^Xi' insert-unicode-char +bindkey '^xi' insert-unicode-char #m# k Shift-tab Perform backwards menu completion if [[ -n "$terminfo[kcbt]" ]]; then @@ -692,6 +703,7 @@ grml_toggle_abbrev() { fi } +#k# Toggle abbreviation expansion on/off zle -N grml_toggle_abbrev bindkey '^xA' grml_toggle_abbrev @@ -885,7 +897,7 @@ abk=( '....' '../../..' 'BG' '& exit' 'C' '| wc -l' - 'G' '|& grep --color=auto ' + 'G' '|& grep '${grep_options:+"${grep_options[*]} "} 'H' '| head' 'Hl' ' --help |& less -r' #d (Display help in pager) 'L' '| less' @@ -916,8 +928,15 @@ zleiab() { LBUFFER+=${abk[$MATCH]:-$MATCH} } -zle -N zleiab -bindkey ",." zleiab +zle -N zleiab && bindkey ",." zleiab + +#f# display contents of assoc array $abk +help-show-abk() +{ + zle -M "$(print "Type ,. after these abbreviations to expand them:"; print -a -C 2 ${(kv)abk})" +} +#k# Display list of abbreviations that expand when followed by ,. +zle -N help-show-abk && bindkey '^xb' help-show-abk # autoloading zrcautoload zmv # who needs mmv or rename? @@ -963,7 +982,7 @@ fi if is4 && zrcautoload insert-files && zle -N insert-files ; then #k# Insert files and test globbing - bindkey "^Xf" insert-files # C-x-f + bindkey "^xf" insert-files # C-x-f fi bindkey ' ' magic-space # also do history expansion on space @@ -994,7 +1013,7 @@ insert-datestamp() { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; } zle -N insert-datestamp #k# Insert a timestamp on the command line (yyyy-mm-dd) -bindkey '^Ed' insert-datestamp +bindkey '^ed' insert-datestamp # press esc-m for inserting last typed word again (thanks to caphuso!) insert-last-typed-word() { zle insert-last-word -- 0 -1 }; @@ -1028,7 +1047,7 @@ sudo-command-line() { zle -N sudo-command-line #k# prepend the current command with "sudo" -bindkey "^Os" sudo-command-line +bindkey "^os" sudo-command-line ### jump behind the first word on the cmdline. ### useful to add options. @@ -1050,7 +1069,7 @@ bindkey '^x1' jump_after_first_word zle -C hist-complete complete-word _generic zstyle ':completion:hist-complete:*' completer _history #k# complete word from history with menu -bindkey "^X^X" hist-complete +bindkey "^x^x" hist-complete ## complete word from currently visible Screen or Tmux buffer. if check_com -c screen || check_com -c tmux; then @@ -1079,8 +1098,8 @@ if check_com -c screen || check_com -c tmux; then compadd -a _screen_display_wordlist } #k# complete word from currently visible GNU screen buffer - bindkey -r "^XS" - compdef -k _complete_screen_display complete-word '^XS' + bindkey -r "^xS" + compdef -k _complete_screen_display complete-word '^xS' fi # history @@ -1452,19 +1471,17 @@ if check_com -c screen ; then fi # do we have GNU ls with color-support? -if ls --help 2>/dev/null | grep -- --color= >/dev/null \ - && [[ "$TERM" != dumb ]] -then +if [[ "$TERM" != dumb ]]; then #a1# execute \kbd{@a@}:\quad ls with colors - alias ls='ls -b -CF --color=auto' + alias ls='ls -b -CF '${ls_options:+"${ls_options[*]} "} #a1# execute \kbd{@a@}:\quad list all files, with colors - alias la='ls -la --color=auto' + alias la='ls -la '${ls_options:+"${ls_options[*]} "} #a1# long colored list, without dotfiles (@a@) - alias ll='ls -l --color=auto' + alias ll='ls -l '${ls_options:+"${ls_options[*]} "} #a1# long colored list, human readable sizes (@a@) - alias lh='ls -hAl --color=auto' + alias lh='ls -hAl '${ls_options:+"${ls_options[*]} "} #a1# List files, append qualifier to filenames \\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...) - alias l='ls -lF --color=auto' + alias l='ls -lF '${ls_options:+"${ls_options[*]} "} else alias ls='ls -b -CF' alias la='ls -la' @@ -1645,7 +1662,7 @@ limit -s # called later (via is4 && grmlcomp) # note: use 'zstyle' for getting current settings -# press ^Xh (control-x h) for getting tags in context; ^X? (control-x ?) to run complete_debug with trace output +# press ^xh (control-x h) for getting tags in context; ^x? (control-x ?) to run complete_debug with trace output grmlcomp() { # TODO: This could use some additional information @@ -2042,7 +2059,7 @@ help_zle_parse_keybindings() if [[ -r $HELP_ZLE_CACHE_FILE ]]; then local load_cache=0 - for f ($KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1 + for f ($HELPZLE_KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1 [[ $load_cache -eq 0 ]] && . $HELP_ZLE_CACHE_FILE && return fi @@ -2050,33 +2067,33 @@ help_zle_parse_keybindings() #Note that due to zsh inconsistency on escaping assoc array keys, we encase the key in '' which we will remove later local -A help_zle_keybindings help_zle_keybindings['@']="set MARK" - help_zle_keybindings['XJ']="vi-join lines" - help_zle_keybindings['XB']="jump to matching brace" - help_zle_keybindings['XU']="undo" + help_zle_keybindings['xj']="vi-join lines" + help_zle_keybindings['xb']="jump to matching brace" + help_zle_keybindings['xu']="undo" help_zle_keybindings['_']="undo" - help_zle_keybindings['XF']="find in cmdline" - help_zle_keybindings['A']="goto beginning of line" - help_zle_keybindings['E']="goto end of line" + help_zle_keybindings['xf']="find in cmdline" + help_zle_keybindings['a']="goto beginning of line" + help_zle_keybindings['e']="goto end of line" help_zle_keybindings['t']="transpose charaters" - help_zle_keybindings['T']="transpose words" + help_zle_keybindings['t']="transpose words" help_zle_keybindings['s']="spellcheck word" - help_zle_keybindings['K']="backward kill buffer" - help_zle_keybindings['U']="forward kill buffer" + help_zle_keybindings['k']="backward kill buffer" + help_zle_keybindings['u']="forward kill buffer" help_zle_keybindings['y']="insert previously killed word/string" help_zle_keybindings["'"]="quote line" help_zle_keybindings['"']="quote from mark to cursor" help_zle_keybindings['']="repeat next cmd/char times (-10a -> -10 times 'a')" - help_zle_keybindings['U']="make next word Uppercase" + help_zle_keybindings['u']="make next word Uppercase" help_zle_keybindings['l']="make next word lowercase" - help_zle_keybindings['Xd']="preview expansion under cursor" + help_zle_keybindings['xd']="preview expansion under cursor" help_zle_keybindings['q']="push current CL into background, freeing it. Restore on next CL" help_zle_keybindings['.']="insert (and interate through) last word from prev CLs" help_zle_keybindings[',']="complete word from newer history (consecutive hits)" help_zle_keybindings['m']="repeat last typed word on current CL" - help_zle_keybindings['V']="insert next keypress symbol literally (e.g. for bindkey)" + help_zle_keybindings['v']="insert next keypress symbol literally (e.g. for bindkey)" help_zle_keybindings['!!:n*']="insert last n arguments of last command" help_zle_keybindings['!!:n-']="insert arguments n..N-2 of last command (e.g. mv s s d)" - help_zle_keybindings['H']="run help on current command" + help_zle_keybindings['h']="show help/manpage for current command" #init global variables unset help_zle_lines help_zle_sln @@ -2146,7 +2163,7 @@ help-zle() zle -M "${(F)help_zle_lines[sln,help_zle_sln-1]}" } #k# display help for keybindings and ZLE (cycle pages with consecutive use) -zle -N help-zle && bindkey '^Xz' help-zle +zle -N help-zle && bindkey '^xz' help-zle # grep for running process, like: 'any vim' any() { @@ -2156,7 +2173,7 @@ any() { echo "any - grep for process(es) by keyword" >&2 echo "Usage: any " >&2 ; return 1 else - ps xauwww | grep -i --color=auto "[${1[1]}]${1[2,-1]}" + ps xauwww | grep -i "${grep_options[@]}" "[${1[1]}]${1[2,-1]}" fi } @@ -2377,7 +2394,7 @@ inplaceMkDirs() { fi } #k# mkdir -p from string under cursor or marked area -zle -N inplaceMkDirs && bindkey '^XM' inplaceMkDirs +zle -N inplaceMkDirs && bindkey '^xM' inplaceMkDirs #f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1 accessed() { @@ -2401,7 +2418,7 @@ check_com new || alias new=modified # use colors when GNU grep with color-support #a2# Execute \kbd{grep -{}-color=auto} -(grep --help 2>/dev/null |grep -- --color) >/dev/null && alias grep='grep --color=auto' +(( $#grml_options > 0 )) && alias grep='grep '${grml_options:+"${grml_options[*]} "}' # Translate DE<=>EN # 'translate' looks up fot a word in a file with language-to-language