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:\/\/(?[^\/]+)\/(?[^\/]+)\/(?.+)$' set --local giturl_format2 '^(ssh:\/\/)?[a-z]+?@(?[^:]+):([0-9]+\/)?(?[^\/]+)\/(?.+)$' 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