1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 02:20:09 +00:00

fix(git): fix smart cd to cloned directory in gccd function

This commit is contained in:
Marc Cornellà 2023-10-19 23:04:08 +02:00
parent f79647dba5
commit ff6dac56a2
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -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