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

Re: tab completion in an alias



On 24 February 2010 06:21, John Magolske <listmail@xxxxxxx> wrote:
> I was impressed to read in the recent post on dirs & popd how
>
>    cd -<tab>
>
> allows one to tabcomplete the directory stack & scroll down through it
> with the <down> key. I'd like to wrap this in an alias that includes
> the <tab>, something like (and I know this doesn't work):
>
>    alias d='cd -       '
>
> So that I could type d, then the enter key, and be presented with the
> directory stack as a menu to scroll down through. Is there some way to
> accomplish this?

I can only think of one, but it's probably too annoying to use:
bindkey -s 'd^M' $'cd -\x09'

There are two problems here:
1) you need to hit enter pretty quickly.
2) there will be a slight pause after every d you type before it appears.

Actually that's a lie, you can do something up like this too
zle -N accept-line my_accept_line_wrapper
function my_accept_line_wrapper() {
  if [[ $BUFFER = d ]]; then
    BUFFER=
    zle -U $'cd -\x09'
    #doing the above sequence by putting the text in $BUFFER and calling
    #zle expand-or-complete doesn't work, the cursor is in the wrong position
    #setting $CURSOR to 4 doesn't seem to help, nor does zle end-of-line
  else
    zle .$WIDGET
  fi
}

-- 
Mikael Magnusson



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