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

Re: cd "" foo bug?



On Fri, Jan 15, 2016 at 10:41:14AM +0000, Peter Stephenson wrote:
> On Fri, 15 Jan 2016 10:45:26 +0100
> Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> > >       cd -- $dir
> > 
> > How is this supposed to work?  The manual does not mention "--":
> 
> You're correct that cd is funny with options, no doubt partly because of
> -<NUM>, so you can forget the "--".  Yes, I think directories beginning
> with "-" are intrinsically somewhat inconsistently handled in the
> builtin (and presumably always have been).

Any chance to at fix "--" so that

  cd -- -1
  cd -- +1
  cd -- -q

actually work?  Currently it's complicated to write a script that
correctly invokes cd with some path P:

  IF P is -<n> or +<n>
    cd "./$P"
  ELSE IF P matches -[qsLP]## (in the sense of extended globbing)
    cd "./$P"
  ELSE IF P is --
    cd -- --
  ELSE
    cd "$P"

With the suggested change you could simply do

  cd -- "$P"

in all cases.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany



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