(bash) fix up clone function
This commit is contained in:
parent
8932858a20
commit
ba8259291a
1 changed files with 7 additions and 7 deletions
|
|
@ -145,15 +145,15 @@ fcd() {
|
||||||
cl() {
|
cl() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local ghq_dir="$HOME/ghq"
|
local ghq_dir="$HOME/ghq"
|
||||||
local project_name=""
|
local namespace=""
|
||||||
local repository_name=""
|
local repository_name=""
|
||||||
|
|
||||||
# extract project name
|
# extract project name
|
||||||
if [[ $url =~ git@git(lab|hub)\.com:([^/]+)/([^/]+)\.git ]]; then
|
if [[ $url =~ git@git(lab|hub)\.com:([^/]+)/([^/]+)\.git ]]; then
|
||||||
local project_name="${BASH_REMATCH[2]}"
|
local namespace="${BASH_REMATCH[2]}"
|
||||||
local repository_name="${BASH_REMATCH[3]}"
|
local repository_name="${BASH_REMATCH[3]}"
|
||||||
elif [[ $url =~ https://git(lab|hub)\.com/([^/]+)/([^/]+)\.git ]]; then
|
elif [[ $url =~ https://git(lab|hub)\.com/([^/]+)/([^/]+)\.git ]]; then
|
||||||
local project_name="${BASH_REMATCH[2]}"
|
local namespace="${BASH_REMATCH[2]}"
|
||||||
local repository_name="${BASH_REMATCH[3]}"
|
local repository_name="${BASH_REMATCH[3]}"
|
||||||
elif [[ $# -ne 0 ]]; then
|
elif [[ $# -ne 0 ]]; then
|
||||||
repository_name=$1
|
repository_name=$1
|
||||||
|
|
@ -172,12 +172,12 @@ cl() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if directory for project exists or not
|
# check if directory for project exists or not
|
||||||
local project_dir="${ghq_dir}/${namespace}/${repository_name}"
|
local repository_dir="${ghq_dir}/${namespace}/${repository_name}"
|
||||||
if [[ ! -d $project_dir ]]; then
|
if [[ ! -d $repository_dir ]]; then
|
||||||
mkdir -p $project_dir
|
mkdir -p $repository_dir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git clone $url $project_dir
|
git clone $url $repository_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
# get branch if available
|
# get branch if available
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue