Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] cd: Append 2nd argument to CWD if 1st is empty
- X-seq: zsh-workers 52350
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Julian Prein <druckdev@xxxxxxxxxxxxxx>
- Cc: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] cd: Append 2nd argument to CWD if 1st is empty
- Date: Fri, 1 Dec 2023 14:51:28 +0100
- Archived-at: <https://zsh.org/workers/52350>
- In-reply-to: <3uINOrbo4IXmuxTPyOMY6U_gv4-qULOThBv5Hd01KcO76FK9AvEFOOIo02fy5VQBIrudqP7rz__wEo1FOG2X2cMLkJzV1wp-1fYkCKYID_8=@protonmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <IZyXHgegIr8a18HfmW1WE7S2UYguBiREgTX0rv0u4WXrJO92IhaP9PVRDvoiEan85dZZL6Gvi4dQeSAgTAiFWitlFReFgse2lMJvCDcsbZM=@protonmail.com> <CAN=4vMrnmJuZ75bgcT94tah8cUDEG6V2fZh=U_u50wdG=TsPxg@mail.gmail.com> <3uINOrbo4IXmuxTPyOMY6U_gv4-qULOThBv5Hd01KcO76FK9AvEFOOIo02fy5VQBIrudqP7rz__wEo1FOG2X2cMLkJzV1wp-1fYkCKYID_8=@protonmail.com>
On 12/1/23, Julian Prein <druckdev@xxxxxxxxxxxxxx> wrote:
> On Friday, December 1st, 2023 at 10:21, Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
>>
>> What is the use case of the new behavior?
>
> I often work in directories that are named the same with one having an
> extra
> suffix. Examples would be ./dotfiles and ./dotfiles-private, or ./repo and
> ./repo-branchname where repo-branchname is a linked git-worktree of repo to
> work
> in different branches simultaneously.
> To switch from repo-branchname to repo, I can type `cd -branchname ''`. The
> inverse does currently not work though; I'd have to type
> `cd ../repo-branchname`.
I'm not opposed to the patch, but you could just cd $PWD-branchname in
this case. It's also easy to get the desired functionality with a
wrapper function (admittedly slightly less easy if you also want to
handle edge cases like cd -L '' foo but you probably don't):
cd() {
if [[ $# == 2 ]] && [[ $1 = "" ]]; then
builtin cd $PWD$2
else
builtin cd "$@"
fi
}
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author