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

Re: [PATCH] expand '..n' to equivalent number of '..' segments in fixdir



On Sat, May 9, 2020 at 9:44 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Sun, May 10, 2020 at 6:36 AM Dian M Fay <dian.m.fay@xxxxxxxxx> wrote:
> >
> > dian@lamia ~/work/zsh cd ..2
> > dian@lamia ~ cd ..123
> > dian@lamia /
>
> `..2` is a valid directory name. So it's a breaking change.

It can also be implemented as a shell function wrapper around "cd", so
it's not necessary to modify the C code.

Here's the basics, minus necessary handling for other cd options.

cd() {
  emulate -L zsh -o extendedglob -o histsubstpattern
  while [[ $1 = (#b)((#s)(|*/)..(<->)(/*|)(#e)) ]] do
    local dots=${(j:/:)${:-{1..${match[3]}}}//<->/..}
    set -- ${1:s,${~match[1]},${match[2]}${dots}${match[4]}}
  done
  echo builtin cd $*
}



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