mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-18 10:22:00 +00:00
fix(git): fix smart cd to cloned directory in gccd
function
This commit is contained in:
parent
f79647dba5
commit
ff6dac56a2
1 changed files with 9 additions and 2 deletions
|
@ -166,8 +166,15 @@ alias gclean='git clean --interactive -d'
|
||||||
alias gcl='git clone --recurse-submodules'
|
alias gcl='git clone --recurse-submodules'
|
||||||
|
|
||||||
function gccd() {
|
function gccd() {
|
||||||
command git clone --recurse-submodules "$@"
|
# get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS
|
||||||
[[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}"
|
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
|
compdef _git gccd=git-clone
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue