mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 19:32:43 +00:00
18 lines
802 B
Fish
18 lines
802 B
Fish
function ghg -a repo
|
|||
|
|
# ghq natively understands https://, ssh://, git@host:…, and host/user/repo
|
||
|
|
ghq get $repo; or return
|
||
|
|
|
||
|
|
# Reduce the input to ghq's on-disk shape: <host>/<user>/<repo>
|
||
|
|
set -l rel (string replace -r '^\w+://' '' -- $repo) # strip scheme (https://, ssh://, git://)
|
||
|
|
set rel (string replace -r '^[^@/]+@' '' -- $rel) # strip user@ (git@github.com:…)
|
||
|
|
set rel (string replace ':' '/' -- $rel) # scp host:path → host/path
|
||
|
|
set rel (string replace -r '\.git$' '' -- $rel) # strip trailing .git
|
||
|
|
|
||
|
|
# bare "user/repo" with no host → default to github.com
|
||
|
|
string match -q '*.*/*' -- $rel; or set rel github.com/$rel
|
||
|
|
|
||
|
|
set -l dir (ghq root)/$rel
|
||
|
|
cd $dir; or return
|
||
|
|
zoxide add $dir
|
||
|
|
clear; and onefetch
|
||
|
|
end
|