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

Re: Completion on dots



2011/8/17 Jesper Nygårds <jesper.nygards@xxxxxxxxx>:
> I have the following in my .zshrc:
>
> alias -g ...='../../'
>
> which of course allows me to write for example "ls ..." to show all
> files in the grand-parent directory.
>
> However, it doesn't work with completion: I can't write "ls
> .../<TAB>", and have zsh complete on the available files in the
> grand-parent directory.
>
> Would it be possible to write such a completion function? And ideally,
> for even more dot patterns: "...", "...." etc, to continue up in the
> file hierachy?

.../ isn't an alias, so it won't work. ls .../foo will also not work,
regardless of completion. This is a better solution,

# just type '...' to get '../..', then additional . adds more /.. segments
_rationalise-dot() {
  local MATCH
  if [[ $LBUFFER =~ '(^|/| |	|'$'\n''|\||;|&)\.\.$' ]]; then
    LBUFFER+=/
    zle self-insert
    zle self-insert
  else
    zle self-insert
  fi
}
zle -N _rationalise-dot
bindkey . _rationalise-dot
# without this, typing a . aborts incremental history search
bindkey -M isearch . self-insert


-- 
Mikael Magnusson



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