Created
June 11, 2023 13:05
-
-
Save cljoly/cbe931d6e0bb31cf9dc113774bb87f3f to your computer and use it in GitHub Desktop.
Quick and dirty alternative to https://github.com/x-motemen/ghq. It only has the features I care about and is much less robust, but it automatically changes the current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ghq | |
# Simplified https://github.com/x-motemen/ghq, so that it’s always available | |
# Reference for git URLs: https://git-scm.com/docs/git-fetch#_git_urls | |
# * ssh://[user@]host.xz[:port]/path/to/repo.git/ | |
# * git://host.xz[:port]/path/to/repo.git/ | |
# * http[s]://host.xz[:port]/path/to/repo.git/ | |
# * ftp[s]://host.xz[:port]/path/to/repo.git/ | |
# * [user@]host.xz:path/to/repo.git/ | |
set -f url $argv[1] | |
set -f path | |
set -f host | |
string match -rq '^([a-z]+://([^@]+@)?(?<host>[^:/]+)(:\d+)?/)(?<path>.+?)(\.git/?)?$' $url || string match -rq '^(([\w-]+@)?(?<host>[^/:@]+):)(?<path>.+?)(\.git/?)?$' $url | |
set -f hqpath "$HOME/ghq/$host/$path" | |
if test ! -d $hqpath | |
echo "Cloning to $hqpath" | |
git clone $url $hqpath | |
end | |
cd $hqpath | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment