Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
cd to a file
- X-seq: zsh-users 11404
- From: Andy Spiegl <zsh.Andy@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: cd to a file
- Date: Mon, 16 Apr 2007 16:40:16 +0200
- In-reply-to: <200406210039.i5L0dsrq022663@xxxxxxxxxxxxxxxxxxxx>
- Kreccount: 1
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <vlc8d0toqggtc9gvlicp20ugllqlh0f7qa@xxxxxxx> <200406210039.i5L0dsrq022663@xxxxxxxxxxxxxxxxxxxx>
Hi,
a long while ago Drew Perttula <drewp@xxxxxxxxxxxxxxxxxxx> posted this very
useful function:
> # cd to a file should take you to the dir that contains the file
> # courtesy of Artur Penttinen <artur@xxxxxxxxxxx>
> function cd () {
> if [[ -f $1 ]]; then
> builtin cd $1:h
> else
> builtin cd $1
> fi
> }
I just noticed that it breaks cd substitution (cd with 2 arguments)
and patched it like this:
# cd to a file should take you to the dir that contains the file
# courtesy of Artur Penttinen <artur@xxxxxxxxxxx>
function cd () {
if [[ -n $2 ]]; then
builtin cd $1 $2
elif [[ -f $1 ]]; then
builtin cd $1:h
else
builtin cd $*
fi
}
Could still be optimized though, I guess.
Andy.
--
Fotos: familie.spiegl.de Info: peru.spiegl.de
Weblog: blog.spiegl.de Mail: andy@xxxxxxxxx
--
Finagle's Second Law:
No matter what the anticipated result, there will always be
someone eager to (a) misinterpret it, (b) fake it, or (c) believe
it happened according to his own pet theory.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author