Skip to content

Instantly share code, notes, and snippets.

@cljoly
Created June 11, 2023 13:05
Show Gist options
  • Save cljoly/cbe931d6e0bb31cf9dc113774bb87f3f to your computer and use it in GitHub Desktop.
Save cljoly/cbe931d6e0bb31cf9dc113774bb87f3f to your computer and use it in GitHub Desktop.

Revisions

  1. cljoly created this gist Jun 11, 2023.
    19 changes: 19 additions & 0 deletions ghq.fish
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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