Question

I find myself doing stuff like typing the last part of a command name because the beginning of it gets completed with other commands. Of course most other shells can't even complete stuff in this way yet.

Anyway, as an example, I've got a script in my $PATH called git-verbose-status or something like that. Along with many others prefixed with git-. It then becomes increasingly difficult to differentiate between them as the prefix-namespace is populated. It really makes sense to think "git" because I named my program that for a reason.

So it got me thinking. A most-recently-used ordering can be used on the string already-typed in order to perform matching. This should be strictly more helpful than doing completion alphabetically as I believe it is normally done.

It could just be a simple reverse scan on command history.

Was it helpful?

Solution

I think the history substring search does exactly what you want; I have setup the following keybindings

bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey '^P' up-line-or-search
bindkey '^N' down-line-or-search

That way I start typing any part of a previous command, press the up-arrow or Ctrl-P and get commands matching that written part anywhere from my history in reverse order - as you described.

Edit: And of course, if you don't want to install the history-search plugin, C-r does also match complete command lines in your history.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top