zsh-users
 help / color / mirror / code / Atom feed
* Tip of the day: previous command output
@ 2004-08-19  8:58 Jesper Holmberg
  2004-08-19 15:20 ` Bart Schaefer
  2004-08-31 15:03 ` zzapper
  0 siblings, 2 replies; 23+ messages in thread
From: Jesper Holmberg @ 2004-08-19  8:58 UTC (permalink / raw)
  To: Zsh-users List

Someone asked for zsh tips a couple of weeks ago. Here's something I use
a lot. I got the basic idea from some user group somewhere, and then I've
tweaked the idea to suit my needs.

The motivation for the following snippet is the fact that I often do a 'find'
or a 'locate' to find some files I'm interested in, and then want to do some
action on one of the files I just found. This function provides a way to put
completions from the output of the previous command on the command line.

_jh-prev-result () {
    hstring=$(eval `fc -l -n -1`)
    set -A hlist ${(@s/
/)hstring}
    compadd - ${hlist}
}

zle -C jh-prev-comp menu-complete _jh-prev-result
bindkey '\ee' jh-prev-comp


What this does is that it repeats the previous command, saving the output
in a string. It then splits the output string on new-lines, and quotes
each element (so that for example file names containing spaces get
properly quoted). I then bind the function to a menu-complete-like widget,
so that I can step through the alternatives.

Test it together with 'loocate' or 'find'. Perhaps someone finds this
useful, and any suggestions for improvement would be appreciated.

Jesper


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2004-08-31 15:05 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-19  8:58 Tip of the day: previous command output 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
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

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).