Menu tab completion for recent history in zsh

Posted by dat5h on Super User See other posts from Super User or by dat5h
Published on 2012-03-30T03:30:27Z Indexed on 2012/03/30 5:34 UTC
Read the original article Hit count: 531

I am interested in a potential zle widget for zsh. Is there a way to build a widget that mimics the kill-completion selectable menu? Essentially I want to be able to press , tab in vi-command-mode, or maybe !-tab-completion at the shell and get a list of recent history (or related history compared what is already entered at the commandline) that allows me to scroll through it and possibly select a relevant function to call or compare similar calls.

Looking through the manual I stumbled onto a similar widget that I have mapped like so:

# tab completion history menu (vicmd)
autoload -z history-beginning-search-menu
zle -N history-beginning-search-menu-space-end history-beginning-search-menu
bindkey -M vicmd "\t"  history-beginning-search-menu-space-end
# emacs binding could be "\e\t"? (I wouldn't know)

Therefore, if I enter vicmd and hit tab when I enter something like "grep", then I get a list of all grep calls in history. It also asks me for the list-number and it will perform the numbered item in history. If I enter a space and then try this, it lists ALL of my history history. This is fairly close to what I want, but there are some problems. For example, 1) it prints the entire list of relevant history and does not check the number of lines of the screen so it could easily blow up the space on the terminal; 2) when I type in numbers for selecting an item in history it does not show me the numbers I type, so I may make a mistake and have to start over again; 3) I would love to be able to hook in appearance tweaks.

I was wondering if there exists more updated version of this widget or if there is any way to look at the source for kill-completion or history-beginning-search-menu to see if I could think of a way to do it.

© Super User or respective owner

Related posts about zsh

Related posts about tab-completion