zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Command Utility Belt
Date: Fri, 20 Jan 2006 02:11:32 +0000	[thread overview]
Message-ID: <1060120021132.ZM18380@candle.brasslantern.com> (raw)
In-Reply-To: <20060119193721.GA8560@namib.cs.utk.edu>

On Jan 19,  2:37pm, Chris Johnson wrote:
}
} I'm finding that I have a lot of semi-often used commands that aren't
} exactly appropriate for aliasing -- they need minor editing each time I
} call on them.
} 
} [...]
} 
} Has anyone else implemented such a "command utility belt" and have
} recommendations?

I do this with the completion system.

In a directory in my fpath I have a file whose name begins with an
underscore with contents like so:

---- 8< --- snip --- 8< ----
#compdef -k menu-select ^X:
(( CURRENT == 1 )) || return 1
local -a commands
commands=(${(f)"$(cat)"}) <<\EOF
 ... a list of commands here, one per line ...
EOF
compadd -Q "$commands[@]"
---- 8< --- snip --- 8< ----

This installs itself during "compinit" so when I type control-X colon
in "command position" I get a menu of the listed commands.

The reason this is restricted to command position is, completion does
not deal well with matches that contain multiple result words.  It
really wants to operate on a single IFS-delimited word only.  When an
entire command -- which might contain command separators, quotes, and
so on -- gets inserted into the command line by the first pass through
completion, all bets are off on the next iteration.  In the command
position, and with menu selection explicitly invoked, completion does
not have a chance to get confused until after you've committed to a
particular choice.

A potentially useful extension to this would be to store the list of
commands outside the actual function, and have another key binding
to append the current command to the file.  This could probably be
done with the push/pop history mechanism, which didn't exist at the
time I wrote this.

In fact, a possible alternative to using completion is a keybinding
that pushes a new history file and does a recursive edit until you
select a command, then restores the old history and calls accept-line.
I may even fool around with that ...


      reply	other threads:[~2006-01-20  2:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-19 19:37 Chris Johnson
2006-01-20  2:11 ` Bart Schaefer [this message]

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=1060120021132.ZM18380@candle.brasslantern.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).