1 # Filename: /etc/zsh/keephack
2 # Purpose: this file belongs to the zsh setup (see /etc/zsh/zshrc)
3 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports: see http://grml.org/bugs/
5 # License: This file is licensed under the GPL v2.
6 # Latest change: Don Jän 27 23:38:57 CET 2005 [mika]
7 ################################################################################
9 # save output in a variable for later use
10 # Written by Bart Schaefer, for more details see:
11 # http://www.zsh.org/cgi-bin/mla/wilma_hiliter/users/2004/msg00894.html ff.
13 setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob
14 kept=() # Erase old value in case of error on next line
19 kept+=( $line ) # += is a zsh 4.2+ feature
22 print -Rc - ${^kept%/}(T)
25 # locate -i backup | grep -i thursday | keep
30 # patch < mypatch.diff
31 # keep **/*.(orig|rej)
32 # vim ${${kept:#*.orig}:r}
34 alias keep='noglob keep'
37 (( $#kept )) || return 1
39 zstyle -s :completion:$curcontext insert-kept action
41 then compstate[insert]=$action
42 elif [[ $WIDGET = *expand* ]]
43 then compstate[insert]=all
45 if [[ $WIDGET = *expand* ]]
46 then compadd -U ${(M)kept:#${~words[CURRENT]}}
51 # now bind it to keys and enable completition
52 zle -C insert-kept-result complete-word _generic
53 zle -C expand-kept-result complete-word _generic
54 zstyle ':completion:*-kept-result:*' completer _insert_kept
55 zstyle ':completion:insert-kept-result:*' menu yes select
57 bindkey '^Xk' insert-kept-result
58 bindkey '^XK' expand-kept-result # shift-K to get expansion
60 # And the "_expand_word_and_keep" replacement for _expand_word:
61 _expand_word_and_keep() {
64 zparseopts -E -A args J:
65 if [[ $args[-J] == all-expansions ]]
67 builtin compadd -A kept "$@"
68 kept=( ${(Q)${(z)kept}} )
72 # for older versions of zsh:
74 _main_complete _expand
78 # versions >=4.2.1 understand this:
79 # { _main_complete _expand } always { unfunction compadd }
82 # This line must come after "compinit" in startup:
83 zle -C _expand_word complete-word _expand_word_and_keep
84 # No bindkey needed, it's already ^Xe from _expand_word
85 zstyle ':completion:*' insert-kept menu
86 zmodload -i zsh/complist
88 ## END OF FILE #################################################################