Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Edit result of last command
- X-seq: zsh-users 8255
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zzapper <david@xxxxxxxxxx>
- Subject: Re: Edit result of last command
- Date: Tue, 30 Nov 2004 18:38:19 -0800 (PST)
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <j7toq0hhu6ldk794e0784rqo1h3oipmcud@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <bgumq0t5rug96h15dd97mf3ik6n7l09u36@xxxxxxx> <Pine.LNX.4.61.0411291151590.25119@xxxxxxxxxxxxxxxxxx> <j7toq0hhu6ldk794e0784rqo1h3oipmcud@xxxxxxx>
- Reply-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
On Tue, 30 Nov 2004, zzapper wrote:
> Any chance you could repost your version of keep ?
I see you found something, but you also asked back then if I could
summarize the thread, and I found a message sitting in my drafts folder
where clearly I intended to do that. So, here in one place, is the end
result of the thread, with a couple of corrections thrown in.
The "keep" function and alias:
function keep {
setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob
kept=() # Erase old value in case of error on next line
kept=($~*)
if [[ ! -t 0 ]]; then
local line
while read line; do
kept+=( $line ) # += is a zsh 4.2+ feature
done
fi
print -Rc - ${^kept%/}(T)
}
alias keep='noglob keep'
The "_insert_kept" widget:
_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
fi
if [[ $WIDGET = *expand* ]]
then compadd -U ${(M)kept:#${~words[CURRENT]}}
else compadd -a kept
fi
}
zle -C insert-kept-result complete-word _generic
zle -C expand-kept-result complete-word _generic
zstyle ':completion:*-kept-result:*' completer _insert_kept
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() {
function compadd() {
local -A args
zparseopts -E -A args J:
if [[ $args[-J] == all-expansions ]]
then
builtin compadd -A kept "$@"
kept=( ${(Q)${(z)kept}} )
fi
builtin compadd "$@"
}
local result
_main_complete _expand
result=$?
unfunction compadd
return result
}
# 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author