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

Re: cd to a file



Atom Smasher <atom@xxxxxxxxxxx>:
> not nearly as elaborate as Frank Terbeck's function, but i think this 
> provides the basic functionality to cd to a file without breaking 
> anything. the "echo" command is very much optional...

Hm, I actually think, that my wrapper works for most (all?) possible
invocations of the 'cd' builtin.

> cd() {
>    ## cd to a file
>    if [ 1 = "${#}" ] && [ '-' != "${1}" ] && [ \! -d "${1}" ] && [ -d "${1:h}" ]
>    then
>      echo "correcting \"${1}\" to \"${1:h}\"" >&2
>      builtin cd "${1:h}"
>    else
>      builtin cd "${@}"
>    fi
> }

This breaks things like 'cd -2', 'cd +2' or 'cd +'.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



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