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 Dez 06 23:21:30 CET 2007 [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
17 if [[ ! -t 0 ]] ; then
20 kept+=( $line ) # += is a zsh 4.2+ feature
24 print -Rc - ${^kept%/}(T)
27 # locate -i backup | grep -i thursday | keep
32 # patch < mypatch.diff
33 # keep **/*.(orig|rej)
34 # vim ${${kept:#*.orig}:r}
36 alias keep='noglob keep'
39 (( $#kept )) || return 1
41 zstyle -s :completion:$curcontext insert-kept action
43 if [[ -n $action ]] ; then
44 compstate[insert]=$action
45 elif [[ $WIDGET == *expand* ]] ; then
48 if [[ $WIDGET == *expand* ]] ; then
49 compadd -U ${(M)kept:#${~words[CURRENT]}}
55 # now bind it to keys and enable completition
56 zle -C insert-kept-result complete-word _generic
57 zle -C expand-kept-result complete-word _generic
58 zstyle ':completion:*-kept-result:*' completer _insert_kept
59 zstyle ':completion:insert-kept-result:*' menu yes select
61 bindkey '^Xk' insert-kept-result
62 bindkey '^XK' expand-kept-result # shift-K to get expansion
64 # And the "_expand_word_and_keep" replacement for _expand_word:
65 _expand_word_and_keep() {
68 zparseopts -E -A args J:
69 if [[ $args[-J] == all-expansions ]] ; then
70 builtin compadd -A kept "$@"
71 kept=( ${(Q)${(z)kept}} )
75 # for older versions of zsh:
77 _main_complete _expand
81 # versions >=4.2.1 understand this:
82 # { _main_complete _expand } always { unfunction compadd }
85 # This line must come after "compinit" in startup:
86 zle -C _expand_word complete-word _expand_word_and_keep
88 # No bindkey needed, it's already ^Xe from _expand_word
89 zstyle ':completion:*' insert-kept menu
90 zmodload -i zsh/complist
92 ## END OF FILE #################################################################
93 # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4