From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Tip of the day: previous command output
Date: Fri, 20 Aug 2004 21:25:47 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.61.0408200905300.27591@toltec.zanshin.com> (raw)
In-Reply-To: <20040820145032.GH13530@ay.vinc17.org>
On Fri, 20 Aug 2004, Andy Spiegl wrote:
> What would be the difference if I dropped alias with the noglob and used
> $* instead of $~*? I guess zsh would expand the globs before calling
> the function, right?
Right.
> But the result should be the same or not?
Should be the same. Waiting to expand uses a little less memory.
On Fri, 20 Aug 2004, Vincent Lefevre wrote:
> On 2004-08-20 11:30:44 +0200, Andy Spiegl wrote:
> > Hm, wouldn't it be a nice feature in general to have zsh always remember
> > the output of the last command, i.e. an automagic "keep"?
>
> This would be nice, but I assume that there would be similar problems
> to stderr coloring (if you remember the thread...).
Exactly right, Vincent.
On Fri, 20 Aug 2004, Andy Spiegl wrote:
> Now that I've got the list of lines (typically filenames) in $kept
> how do I get them into the command line _quoted_.
The best way is probably to use a completion widget.
insert-kept-result () {
compstate[insert]=all
compadd -a kept
}
zle -C insert-kept-result complete-word insert-kept-result
> Actually, ideally I'd like only filenames with spaces and special chars
> to be quoted to avoid cluttering up the command line, but I assume
> that's even tougher to do. :-(
Not with completion, it isn't.
As a bonus, if you type part of a word and then invoke insert-kept-result
it'll only insert the subset of $kept that matches the partial word.
On Fri, 20 Aug 2004, Vincent Lefevre wrote:
> On 2004-08-20 14:12:02 +0200, Andy Spiegl wrote:
> > Now that I've got the list of lines (typically filenames) in $kept
> > how do I get them into the command line _quoted_.
>
> And would it be possible to get a menu, in order to select one or
> several filenames manually?
For that we get a little more intense:
_insert_kept() {
(( $#kept )) || return 1
local action
zstyle -s :completion:$curcontext insert-kept action
if [[ -n $action ]]
then compstate[insert]=$action
fi
compadd -a kept
}
zle -C insert-kept-result complete-word _generic
zstyle ':completion:insert-kept-result:*' completer _insert_kept
Now you get Andy's thing with
zstyle ':completion:*' insert-kept all
Or you can get menu completion with
zstyle ':completion:*' insert-kept menu
and it does menu completion according to whatever your other usual styles
are (or you can add other specific styles for this context).
Just remember that TAB is still going to execute _main_complete directly,
so if you start whacking TAB to cycle through the menu you won't get very
far -- the normal completion context will take over and discard the list
taken from $kept. You have to use the same keybinding to cycle as you did
to get into the menu to begin with.
Note also that if you simply stick _insert_kept into your normal completer
style, the TAB key will insert values from $kept when it has a value and
go on to use other completions when $kept is empty or unset.
> And how about typing a pattern somewhere in the command line, then
> applying a function that replaces this pattern by the matching lines
> (quoted) of $kept?
You'll have to be more specific. You mean something like expand-word,
except that the expansion gets stashed in $kept first?
I won't try to test this, but something like this should do it:
_expand_word_and_keep() {
function compadd() {
local -a args
zparseopts -E -a args A: O:
if (( ! $#args ))
then builtin compadd -A kept "$@"
fi
builtin compadd "$@"
}
local result
kept=()
_main_complete _expand
result=$?
unfunction compadd
return $result
}
See the #compdef line at the top of the _expand_word function file in the
distribution for how you'd plug that onto a key.
Hmm, it occurs to me that I'm not sure what happens when you combine the
-A and -C options of compadd ...
next prev parent reply other threads:[~2004-08-21 4:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-19 8:58 Jesper Holmberg
2004-08-19 15:20 ` Bart Schaefer
2004-08-19 16:42 ` Andy Spiegl
2004-08-19 17:16 ` Bart Schaefer
2004-08-20 9:30 ` Andy Spiegl
2004-08-20 11:13 ` Vincent Lefevre
2004-08-20 12:12 ` Andy Spiegl
2004-08-20 14:50 ` Vincent Lefevre
2004-08-21 4:25 ` Bart Schaefer [this message]
2004-08-21 5:58 ` Bart Schaefer
2004-08-21 17:06 ` Bart Schaefer
2004-08-22 20:58 ` Vincent Lefevre
2004-08-23 1:10 ` Bart Schaefer
2004-08-23 13:51 ` Vincent Lefevre
2004-08-22 21:21 ` Vincent Lefevre
2004-08-22 23:03 ` Bart Schaefer
2004-08-23 13:00 ` Vincent Lefevre
2004-08-23 15:21 ` Bart Schaefer
2004-08-23 19:14 ` Vincent Lefevre
2004-08-26 23:16 ` Andy Spiegl
2004-08-27 0:43 ` Bart Schaefer
2004-08-27 10:21 ` Andy Spiegl
2004-08-31 15:03 ` zzapper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.61.0408200905300.27591@toltec.zanshin.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).