Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: commandline "macro"

On May 22,  1:07am, Eric Smith wrote:
} Subject: commandline "macro"
} Is there a way to map to a key combination certain strings that then come
} up on the command line?  You may then further edit whatever appears.

Look at "bindkey -s ...".

} Similiar to searching your history file and having a previous command
} come up but in this case the commands are stored in your rc file.

If you mean you want to have a set of keystrokes that lets you scroll
through a list of commands and choose one to edit, you're probably best
off making use of the new completion system in (soon-to-be) 3.1.7.

Something like this, which you name whatever you want and put into a
directory in $fpath so compinit will see it:

---- 8< ---- snip ---- 8< ----
#compdef -k menu-complete ^X:
local -a commands
commands=(${(f)"$(cat)"}) <<\EOF
echo Put any commands you like here,
echo as long as they don\'t need embedded newlines.
: 'This is a hack because a here-document does not work in $(...),'
: in fact it puts the parser into state from which it can never
: correctly return.
compadd -Q "$commands[@]"
---- 8< ---- snip ---- 8< ----

Now you can type ^X: and then TAB your way through the commands, or set
up styles to start menu-selection, or whatever.

It does beep a lot when I try it, for reasons I'm too heat-oppressed to
figure out just now (Sven?), but it works.  

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Messages sorted by: Reverse Date, Date, Thread, Author