Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: a little problem with the second argument to cd
- X-seq: zsh-users 6617
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: a little problem with the second argument to cd
- Date: Thu, 25 Sep 2003 04:47:36 +0000
- In-reply-to: <20030924161638.GG32061@xxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20030924135231.GB32061@xxxxxx> <1030924153602.ZM30551@xxxxxxxxxxxxxxxxxxxxxxx> <20030924155949.GE32061@xxxxxx> <20030924161638.GG32061@xxxxxx>
On Sep 24, 6:16pm, Dominik Vogt wrote:
>
> Well, I thought someone else might be interested in my cd
> function:
>
> 1 Argument
>
> - If the argument is a directory name it cds into it.
> - If the name ends with a colon, and a directory with the colon
> stripped from the name exists, it cds into it. (Usefull for
> cut-and-paste).
> - If the argument is a file and the file name ends in .tar.gz,
> .tar.bz2, .tgz, .TGZ, .zip or .ZIP, it strips the suffix and
> cds into the directory with that name (if there is one).
> - If the argument is a plain file, it cds into the directory in
> which the file resides.
> - If all the above attempts fail, works like "builtin cd $1".
This sounds very interesting, but it looks like your implementation
could be a bit more zsh-ish. No reason to process-substitute with
dirname and basename when zsh can do that stuff itself!
local DIR="$1:h"
local STRIP="$1:r"
local EXT="$1:e"
if [[ "$EXT" == .(gz|bz2) && "$STRIP" == *.tar ]]; then
STRIP="$STRIP:r"
EXT=".tar$EXT"
fi
if [[ -d "$1" ]]; then
builtin cd "$1"
elif [[ "$EXT" == .(tar.(gz|bz2)|tgz|zip|TGZ|ZIP) &&
-d "$STRIP" ]]; then
builtin cd "$STRIP"
elif [[ -f "$1" ]]; then
builtin cd "$DIR"
else
builtin cd "$1"
fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author