X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fkeephack;h=7d4788c5cb2959daa70e59b6d22eb7cb3f43b111;hb=aaa1e7fa0cf1a864cb163b212c9b9b8a8488541d;hp=d4c8a5f0e5a54d514d5125a7273624f5b9e02955;hpb=fdc8e8a0089fc457478464f8cbe4b89a813b27fc;p=grml-etc-core.git diff --git a/etc/zsh/keephack b/etc/zsh/keephack index d4c8a5f..7d4788c 100644 --- a/etc/zsh/keephack +++ b/etc/zsh/keephack @@ -3,86 +3,90 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Don Jän 27 23:38:57 CET 2005 [mika] ################################################################################ # save output in a variable for later use # Written by Bart Schaefer, for more details see: # http://www.zsh.org/cgi-bin/mla/wilma_hiliter/users/2004/msg00894.html ff. - function keep { +function keep { setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob kept=() # Erase old value in case of error on next line kept=($~*) - if [[ ! -t 0 ]]; then + + if [[ ! -t 0 ]] ; then local line while read line; do kept+=( $line ) # += is a zsh 4.2+ feature done fi + print -Rc - ${^kept%/}(T) - } - # use it via: - # locate -i backup | grep -i thursday | keep - # echo $kept - # - # or: - # - # patch < mypatch.diff - # keep **/*.(orig|rej) - # vim ${${kept:#*.orig}:r} - # rm $kept - alias keep='noglob keep' +} +# use it via: +# locate -i backup | grep -i thursday | keep +# echo $kept +# +# or: +# +# patch < mypatch.diff +# keep **/*.(orig|rej) +# vim ${${kept:#*.orig}:r} +# rm $kept +alias keep='noglob keep' - _insert_kept() { +_insert_kept() { (( $#kept )) || return 1 local action zstyle -s :completion:$curcontext insert-kept action - if [[ -n $action ]] - then compstate[insert]=$action - elif [[ $WIDGET = *expand* ]] - then compstate[insert]=all + + if [[ -n $action ]] ; then + compstate[insert]=$action + elif [[ $WIDGET == *expand* ]] ; then + compstate[insert]=all fi - if [[ $WIDGET = *expand* ]] - then compadd -U ${(M)kept:#${~words[CURRENT]}} - else compadd -a kept + if [[ $WIDGET == *expand* ]] ; then + compadd -U ${(M)kept:#${~words[CURRENT]}} + else + compadd -a kept fi - } +} - # now bind it to keys and enable completition - zle -C insert-kept-result complete-word _generic - zle -C expand-kept-result complete-word _generic - zstyle ':completion:*-kept-result:*' completer _insert_kept - zstyle ':completion:insert-kept-result:*' menu yes select +# now bind it to keys and enable completition +zle -C insert-kept-result complete-word _generic +zle -C expand-kept-result complete-word _generic +zstyle ':completion:*-kept-result:*' completer _insert_kept +zstyle ':completion:insert-kept-result:*' menu yes select - bindkey '^Xk' insert-kept-result - bindkey '^XK' expand-kept-result # shift-K to get expansion +bindkey '^Xk' insert-kept-result +bindkey '^XK' expand-kept-result # shift-K to get expansion - # And the "_expand_word_and_keep" replacement for _expand_word: - _expand_word_and_keep() { +# And the "_expand_word_and_keep" replacement for _expand_word: +_expand_word_and_keep() { function compadd() { local -A args zparseopts -E -A args J: - if [[ $args[-J] == all-expansions ]] - then + if [[ $args[-J] == all-expansions ]] ; then builtin compadd -A kept "$@" kept=( ${(Q)${(z)kept}} ) fi builtin compadd "$@" } # for older versions of zsh: - local result - _main_complete _expand - result=$? - unfunction compadd - return result + local result + _main_complete _expand + result=$? + unfunction compadd + return result # versions >=4.2.1 understand this: # { _main_complete _expand } always { unfunction compadd } - } +} + +# This line must come after "compinit" in startup: +zle -C _expand_word complete-word _expand_word_and_keep - # This line must come after "compinit" in startup: - zle -C _expand_word complete-word _expand_word_and_keep - # No bindkey needed, it's already ^Xe from _expand_word - zstyle ':completion:*' insert-kept menu - zmodload -i zsh/complist +# No bindkey needed, it's already ^Xe from _expand_word +zstyle ':completion:*' insert-kept menu +zmodload -i zsh/complist ## END OF FILE ################################################################# +# vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4