feat(shell): add my-clone command for cloning git repertories
When cloning a repo I have all of the repertories structured on the file system by "host" "group" then "name". This command will automatically clone the repo into the correct directory based on the name and the move into the cloned repo directory. An example of a repo to be cloned is the dotfiles repo has the URL of `git@gitlab.com:AdeAttwood/dotfiles.git` so on the file system it will be in the source directory `gitlab.com/AdeAttwood/dotfiles`. This keep all of the repos well structured and searchable.
This commit is contained in:
parent
13845d5098
commit
bc512c7e5d
1 changed files with 19 additions and 0 deletions
|
|
@ -30,5 +30,24 @@ function grc() {
|
|||
git commit -t "$(git rev-parse --show-toplevel)/.git/COMMIT_TEMPLATE"
|
||||
}
|
||||
|
||||
function my-clone() {
|
||||
local url="$1"
|
||||
local re="^(https|git)(:\/\/|@)([^\/:]+)[\/:](.*?).git$"
|
||||
|
||||
if [[ -z "$url" ]]; then
|
||||
echo "ERROR: Invalid url"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $url =~ $re ]]; then
|
||||
local protocol="${match[1]}"
|
||||
local separator="${match[2]}"
|
||||
local hostname="${match[3]}"
|
||||
local repo="${match[4]}"
|
||||
|
||||
full_path=~s/$hostname/$repo
|
||||
|
||||
git clone $url ~s/$hostname/$repo
|
||||
cd ~s/$hostname/$repo
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue