I find myself doing <command> --help | grep <feature>
very very often everyday. I was wondering if it was possible to make something like ^^
that expands to "--help | grep"
and then I do this:
ls ^^ size
That would execute the following:
ls --help | grep size
Best Answer
With
zsh
, you'd use a global alias:With
bash
, you may be able to use history expansion which is one that happens early enough in the shell syntax parsing that it can work at substituting a pipe:Prime the history with a the text you want to substitute and a special character you're unlikely to use otherwise (like
£
here that happens to be on my keyboard):Then using history expansion to retrieve that:
Or you could have
readline
expand--help|grep
upon some key or key sequence press. For that to apply tobash
only (and not other applications likegdb
using readline), you can use thebind
bash builtin command which isbash
's API to configuringreadline
, for instance in your~/.bashrc
:Or add to your
~/.inputrc
(readline's configuration file):(there are other shells like
rc
ores
that use readline and where doing that binding could make sense but AFAICT, they do not set therl_readline_name
variable before invokingreadline
so you won't be able to add some$if
statements for them (they would show asother
like all applications that use readline without telling it their application name)).Note that you need to enter the second
^
within half a second (by default) after the first one for the substitution to occur.