25 lines
897 B
Fish
25 lines
897 B
Fish
function clone --argument-names giturl
|
|
# These regular expressions are far from comprehensive, but they work for me.
|
|
#
|
|
# Examples:
|
|
# https://github.com/NixOS/nix
|
|
# https://git.sr.ht/~sircmpwn/git.sr.ht
|
|
# git@git.sr.ht:~crg/home
|
|
# ssh://git@gitlab.haskell.org:ghc/ghc.git
|
|
#
|
|
set --local giturl_format1 '^https:\/\/(?<githost>[^\/]+)\/(?<gituser>[^\/]+)\/(?<gitrepo>.+)$'
|
|
set --local giturl_format2 '^(ssh:\/\/)?[a-z]+?@(?<githost>[^:]+):([0-9]+\/)?(?<gituser>[^\/]+)\/(?<gitrepo>.+)$'
|
|
|
|
string match -rq $giturl_format1 $giturl; or string match -rq $giturl_format2 $giturl
|
|
|
|
set gituser (string replace '~' '' $gituser)
|
|
set gitrepo (string replace -r '.git$' '' $gitrepo)
|
|
|
|
set --local gitdir "$HOME/Code/$githost/$gituser/$gitrepo"
|
|
|
|
if confirm "Clone to $gitdir?"
|
|
git clone $giturl "$gitdir"
|
|
cd "$gitdir"
|
|
end
|
|
end
|