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

Re: Implement CDPATH mechanism in Zsh script



On Sep 7,  8:13am, Sebastian Gniazdowski wrote:
}
} On 7 September 2016 at 08:04, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
} wrote:
} 
} > Or are you trying to predict how the current directory is going to be
} > changed by "cd", without actually executing "cd"?
} 
} Ah, it's about prediction

The most obvious/foolproof thing would be to use a subshell:

    newPWD=$(cd -q $where >&/dev/null && pwd)

Next would be globbing:

    # Assumes last component of $cdpath is "."
    cdWD=( $^cdpath/$where(N[1]) )
    newPWD=${cdWD:A}

Note this is exactly what :A is supposed to be for, but it gives the
wrong result if CHASE_LINKS or CHASE_DOTS is set, so you may need the
new :P modifier, or the :a modifier instead.  [[ -o ... ]] tests left
as an exercise.



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