Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: global aliases substituting *within* a path
On May 18, 3:08pm, Ronald Fischer wrote:
}
} > echo a/f/b/b/x<TAB>
}
} Doesn't help here, for two reason:
}
} (1) At least in my version of zsh (4.3.12), this would not expand the
} interim directories (f,b,b).
Does your zsh configuration include installing the completion system
(the "compinit" command)?
} (2) Even if I could do TAB completion on directories within the path,
} this is not what I'm looking for, because it is still cumbersome to
} type.
You might want to look at named directories:
hash -d aaa=aaa/foo/bar/baz
hash -d bbb=bbb/foo/bar/baz
hash -d ccc=ccc/foo/bar/baz
Then you can write
ls ~aaa/xxx
ls ~bbb/yyy
ls ~ccc/zzz
I don't know how much variation there is in the "foo/bar/baz" part of
your structure. You can try using dynamic named directories:
X=foo/bar/baz
ls ~[aaa/X]/xxx
That's not saving any keystrokes over aaa/$X/xxx but might have some
aesthetic advantages. It's implemented with something like this:
stem_name_hook() {
case $1 in
(n) local root=$2:h stem=$2:t
reply=( $root/${(P)stem} )
;;
(*) return 1;
esac
}
autoload -Uz add-zsh-hook
add-zsh-hook zsh_directory_name stem_name_hook
The above allows ANY leading path (the "root") and ANY variable name (the
"stem") after the slash to be the "middle of the path", e.g.
Y=fare/thee/well
ls ~[/usr/local/Y]/yyy
You could of course apply a similar transformation on the root instead
(or as well) but that's not much different than ordinary "hash -d" with
perhaps auto_name_dirs enabled.
If you want to be able to use it in completions and other automatic path
contractions, you need a reverse mapping that provides a sensible set of
root and stem names. Here's one that uses ONLY aaa, bbb, ccc for roots
and ONLY $X for the stem:
stem_name_hook() {
case $1 in
(n) reply=( $2:h/$X )
;;
(d) reply=( ${2/\/$X(\/*|)/\/X})
reply=($reply ${#reply[1]} )
;;
(c) local dirs
dirs=( (aaa|bbb|ccc)/$X )
if (( $#dirs )); then
dirs=( ${^dirs%$X}X )
_wanted dynamic-dirs expl 'dynamic directory' \
compadd -S \] -a dirs
else
return 1
fi
;;
(*) return 1;
esac
}
I'm not entirely sure about that (c) branch, which is for compsys [cf.
my response to (1)]. PWS is the expert on dynamic directory hooks.
--
Barton E. Schaefer
Messages sorted by:
Reverse Date,
Date,
Thread,
Author