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

Re: '...' in path names?

On Tue, 13 Jun 2000, Dominik Vogt wrote:

> I really like to abbreviate something like '../../..' with '....'
> (you get the idea).  (The last time I tried to get it working was
> zsh-3.0.5).  I didn't get any farther than this:
>   alias '...'='cd ../..'
>   alias '....'='cd ../../..'
>   alias '.....'='cd ../../../..'
>   ...

I posted a partial solution for this in


> which works for '...' in the command position, but not in 'cd ...'.

Same for what I previously posted.

> Any ideas how to improve this situation?
> It would be cool if it were possible to expand strings of dots
> in every path without having to .

Without having to what?

Would you be happy enough doing this with completion, i.e. you type TAB
to expand the dots and then hit return?

# Put this in a file named _expand_dots in your $FPATH, then
# add _expand_dots to the front of the "completer" style, e.g:
#   zstyle ':completion:*' completer _expand_dots _complete
# Requires 3.1.9.

local word sub
local patl='(#b)([^\/])..' patr='(#b)..([^\/])'
local repl='/..' repr='../'

# This first part borrowed from _expand

[[ _matcher_num -gt 1 ]] && return 1

if [[ "$funcstack[2]" = _prefix ]]; then

# The real stuff

setopt localoptions extendedglob


while [[ "$sub" = *...* ]]; do
  sub="${sub/.../../..}"       # Looks odd because the 3rd / isn't magic

[[ "$sub" != "$word" ]] && compadd -QU -S '' "$sub"

If you prefer not to have it expand the dots unless there's a real file or
directory to match, you can change that last line to something like

[[ "$sub" != "$word" && -r "$sub" ]] && compadd -QU -S '' "$sub"

but that may cause undesired effects e.g. for completion along $cdpath.

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