summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarc Cornellà <marc@mcornella.com>2023-10-19 23:04:08 +0200
committerMarc Cornellà <marc@mcornella.com>2023-10-19 23:04:08 +0200
commitff6dac56a256e376a10b19a4948ada7df4509c71 (patch)
tree81a54d3b69e514b0392a1468a1087206466b6518 /plugins
parentf79647dba5df47cd87917bcf527c5825be6511dc (diff)
downloadzsh-ff6dac56a256e376a10b19a4948ada7df4509c71.tar.gz
zsh-ff6dac56a256e376a10b19a4948ada7df4509c71.tar.bz2
zsh-ff6dac56a256e376a10b19a4948ada7df4509c71.zip
fix(git): fix smart cd to cloned directory in `gccd` function
Diffstat (limited to 'plugins')
-rw-r--r--plugins/git/git.plugin.zsh11
1 files changed, 9 insertions, 2 deletions
diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
index eef538b75..6ea1d1177 100644
--- a/plugins/git/git.plugin.zsh
+++ b/plugins/git/git.plugin.zsh
@@ -166,8 +166,15 @@ alias gclean='git clean --interactive -d'
alias gcl='git clone --recurse-submodules'
function gccd() {
- command git clone --recurse-submodules "$@"
- [[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}"
+ # get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS
+ local repo="${${@[(r)(ssh://*|git://*|ftp(s)#://*|http(s)#://*|*@*)(.git/#)#]}:-$_}"
+
+ # clone repository and exit if it fails
+ command git clone --recurse-submodules "$@" || return
+
+ # if last arg passed was a directory, that's where the repo was cloned
+ # otherwise parse the repo URI and use the last part as the directory
+ [[ -d "$_" ]] && cd "$_" || cd "${${repo:t}%.git/#}"
}
compdef _git gccd=git-clone