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

Re: menuselect and history



On Apr 19, 11:52am, Matthias Kopfermann wrote:
> 
> i just wondered whether it wouldn't be very cool if menuselect was
> useable with historylines.

--- 8< --- snip --- 8< ---
#compdef -k menu-select ^X:

# _history_select -- create a menu-selection of the command history

# Works only if invoked on the command word (( CURRENT == 1 )).
# Requires 4.2.0 or a recent 4.1.x for the 'n' parameter flag and
# array+=string assignments.
# BUGS:
#	This doesn't really scroll through the history, it scrolls
#	through commands in the history and re-inserts one as the
#	current history line.  So accept-line-and-down-history will
#	not work as expected, but accept-and-infer-next-history is
#	probably OK.
# TODO:
#	special case for (( HISTSIZE > 9999 ))
#	zstyle for how much of the history to include
#	use the numeric prefix to set the starting point?

emulate -L zsh
zmodload -i zsh/parameter || return 1
(( CURRENT == 1 )) || return 1

local h c
local -a histnos commands displays
histnos=(${(Onk)history})

for h in $histnos
do
  c=$history[$h]
  commands+=$c

  # Various display bugs require that we trim each selection to fit on
  # a single line.  Use a display that includes the history number.
  if [[ $#c -gt 71 ]]; then c[72,-1]=...; fi
  c=${c//$'\n'*/ ...}
  displays+=${(r:5:)${(l:4:)h}}$c
done

compadd -Q -l -V commands -d displays -a commands
--- 8< --- snip --- 8< ---



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