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 ################################################################################
8 # save output in a variable for later use
9 # Written by Bart Schaefer, for more details see:
10 # http://www.zsh.org/cgi-bin/mla/wilma_hiliter/users/2004/msg00894.html ff.
12 setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob
13 kept=() # Erase old value in case of error on next line
16 if [[ ! -t 0 ]] ; then
19 kept+=( $line ) # += is a zsh 4.2+ feature
23 print -Rc - ${^kept%/}(T)
26 # locate -i backup | grep -i thursday | keep
31 # patch < mypatch.diff
32 # keep **/*.(orig|rej)
33 # vim ${${kept:#*.orig}:r}
35 alias keep='noglob keep'
38 (( $#kept )) || return 1
40 zstyle -s :completion:$curcontext insert-kept action
42 if [[ -n $action ]] ; then
43 compstate[insert]=$action
44 elif [[ $WIDGET == *expand* ]] ; then
47 if [[ $WIDGET == *expand* ]] ; then
48 compadd -U ${(M)kept:#${~words[CURRENT]}}
54 # now bind it to keys and enable completition
55 zle -C insert-kept-result complete-word _generic
56 zle -C expand-kept-result complete-word _generic
57 zstyle ':completion:*-kept-result:*' completer _insert_kept
58 zstyle ':completion:insert-kept-result:*' menu yes select
60 bindkey '^Xk' insert-kept-result
61 bindkey '^XK' expand-kept-result # shift-K to get expansion
63 # And the "_expand_word_and_keep" replacement for _expand_word:
64 _expand_word_and_keep() {
67 zparseopts -E -A args J:
68 if [[ $args[-J] == all-expansions ]] ; then
69 builtin compadd -A kept "$@"
70 kept=( ${(Q)${(z)kept}} )
74 # for older versions of zsh:
76 _main_complete _expand
80 # versions >=4.2.1 understand this:
81 # { _main_complete _expand } always { unfunction compadd }
84 # This line must come after "compinit" in startup:
85 zle -C _expand_word complete-word _expand_word_and_keep
87 # No bindkey needed, it's already ^Xe from _expand_word
88 zstyle ':completion:*' insert-kept menu
89 zmodload -i zsh/complist
91 ## END OF FILE #################################################################
92 # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4