Code Monkey home page Code Monkey logo

gh's Introduction

gh

gh allows you to very quickly navigate between GitHub project cloned on your local box. It will cd into project directories quickly and clone repos that do not exist.

There is a lot of mental overhead trying to manage a custom ~/src directory with your projects. I tried managing by work/personal, programming language, even tried a different directory for each month. I found by simply making your projects path reflect GitHub, it was much easier to remember where things were.

Here is a demo of me moving around various projects

demo

Usage

Clone and/or go to ~/src/github.com/githubuser/githubrepo.

gh githubuser githubrepo

It'll either just be a cd or it will clone [email protected]:githubuser/githubrepo.git

Note that tab completion is available for project and usernames.

Changing the base directory

gh will clone or cd into $GH_BASE_DIR/github.com/user/repo. By default $GH_BASE_DIR points to $HOME/src. By changing the $GH_BASE_DIR variable in your shell's config file, you can control where gh will clone/cd into.

Note: Already cloned repos will not be transferred to the new location, they will be cloned again.

More important Note: Do not use the tilde-character (~) in $GH_BASE_DIR, use $HOME instead.

Supported Shells

Installation for bash

echo 'source ~/src/github.com/jdxcode/gh/bash/gh.bash' >> ~/.bashrc
echo 'source ~/src/github.com/jdxcode/gh/completions/gh.bash' >> ~/.bashrc

Installation For Fish

Using oh-my-fish:

omf install gh

Using fisherman:

fisher jdxcode/gh

Alternatively, symlink (or copy) the function and completion files into $fish_function_path and $fish_complete_path

mkdir -p ~/src/github.com/jdxcode
git clone [email protected]:jdxcode/gh.git ~/src/github.com/jdxcode/gh
ln -s ~/src/github.com/jdxcode/gh/functions/gh.fish ~/.config/fish/functions/gh.fish
ln -s ~/src/github.com/jdxcode/gh/completions/gh.fish ~/.config/fish/completions/gh.fish

Installation For Oh-My-ZSH

Add this environment variable for your GitHub username (optional)

typeset +gx -A GITHUB
GITHUB[user]=jdxcode

Then symlink (or copy) the gh folder into your Oh-My-ZSH plugins folder

ln -s ~/src/github.com/jdxcode/gh/zsh/gh ~/.oh-my-zsh/custom/plugins/gh

Next add the plugin to your ~/.zshrc file

plugins=(gh)

For example:

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins=(git brew meteor node npm osx redis-cli sublime gh)

Finally reload the ~/.zshrc file:

source ~/.zshrc

The zsh autocompletion supports loading a user's repositories from github. For that to work, you need to set the environment variable GH_FETCH_REPOS to true. You will also need to install jsawk for it to work.

If you now type gh someusername and then press <Tab>, it will load that user's repositories from github and display them to you.

Note that, if autocompletion isn't working, then you probably need to make zsh refresh the completions dumpfile. Just remove the $HOME/.zcompdump-* file:

rm $HOME/.zcompdump-*

and reload the ~/.zshrc again to regenerate it.

For the bb (bitbucket) equivalent, repeat the above instructions, but substitute gh with bb, i.e.:

ln -s ~/src/github.com/jdxcode/gh/zsh/bb ~/.oh-my-zsh/custom/plugins/bb
plugins=(gh bb)
source ~/.zshrc

As before for GITHUB environment variable, the environment variable BITBUCKET is optional:

typeset +gx -A BITBUCKET
BITBUCKET[user]=jdxcode

Installation for zsh

Zsh supports bash autocomplete. You can add the following to your .zshrc but make sure you have compinit done first.

compinit
...
# bash completion and gh
autoload bashcompinit
bashcompinit
source ~/src/github.com/jdxcode/gh/bash/gh.bash
source ~/src/github.com/jdxcode/gh/completions/gh.bash

GitHub Alternatives

  • bb - bitbucket (fish)
  • gl - gitlab (fish, bash)

Go developers

This follows the standard convention for Go projects so long as you have your GOPATH set to ~.

gh's People

Contributors

ahazem avatar dgmora avatar douganger avatar glor avatar jdx avatar jonathanusername avatar liammcleod avatar mando avatar mec07 avatar patrick96 avatar sammorrowdrums avatar sbarratt avatar skarra avatar tsvayer avatar vertis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gh's Issues

Automatic symlinks?

Sometimes it is not possible (or reasonable) to put my github repos in the src directory. This is especially true for language libraries, which often must be in a specific folder.

I've been symlinking them manually

$ ln -s ~/src/github.com/equwal/clapt ~/common-lisp/clapt/

but it would be nice as a part of gh. Maybe add an flag like -s to the end of the arglist? So:

$ cd ~/common-lisp/clapt
$ gh equwal clapt -s
...symlinking clapt to ~/src/github.com/equwal/clapt/...
$

I have enough repositories littering my disk that I'll be using something like this.

Add protocol option for https clone

By default gh clone via ssh, for my scenario where ssh is blocked by corporate firewall, an option for https clone would be a life saver.

Something like:

gh --protocol=https [user] [repo]

Allow gh githubuser/githubrepo

Just discovered this nice plugin and I think it would be quite practical to allow gh githubuser/githubrepo so you can copy/paste from the url. We just need a small check if the argv contains a / and then split it.

github forks

I often have repos with multiple remotes corresponding to forks on github.
It would be nice if gh had a sensible way to deal with that.

I can think of a couple ideas, e.g., if you gh foo bar when github.com/foo/bar is a fork of github.com/fu/bar which is already gh'ed, then create a symlink and do a git remote add fu xxx; git fetch fu. Or maybe do this only after user confirmation?

As a generalization, it would be nice to be able to gh-forks a repo and have it cloned with all forks added as remotes, and to be able to update this when new forks are created.

Conflict with oh-my-zsh `gh` alias

Hey, I love gh, thanks so much!

I updated oh-my-zsh today and immediately afterwards found that I could only use gh as the git help oh-my-zsh alias. I pulled down the latest version of dickeyxxx/gh which didn't seem to have any effect so I then removed gh and reverted any other setup steps from your Readme, which I then went through again from scratch, also to no avail.

I might be being stupid but I can only get the previous behaviour working again by running unalias gh.

Thought I'd mention here โ€” thanks again for the awesome productivity-enhancing tool! ๐Ÿ˜

gh does not work with fish

fisher dickeyxxx/gh does not work.

Unsupported use of '='. In fish, please use 'set GH_BASE_DIR $GH_BASE_DIR:-$HOME/src'.
~/.config/fish/functions/bb.fish (line 1): GH_BASE_DIR=${GH_BASE_DIR:-$HOME/src}
                                           ^
from sourcing file ~/.config/fish/functions/bb.fish
    called on line 767 of file ~/.config/fish/functions/fisher.fish

in function '__fisher_plugin_enable'
    called on line 639 of file ~/.config/fish/functions/fisher.fish
    with parameter list '/Users/shane/.config/fisherman/gh'

in function '__fisher_update'
    called on line 257 of file ~/.config/fish/functions/fisher.fish
    with parameter list 'dickeyxxx/gh'

in function 'fisher'
    called on standard input
    with parameter list 'update dickeyxxx/gh'

Unsupported use of '='. In fish, please use 'set GH_BASE_DIR $GH_BASE_DIR:-$HOME/src'.
~/.config/fish/functions/gh.fish (line 1): GH_BASE_DIR=${GH_BASE_DIR:-$HOME/src}
                                           ^
from sourcing file ~/.config/fish/functions/gh.fish
    called on line 767 of file ~/.config/fish/functions/fisher.fish

in function '__fisher_plugin_enable'
    called on line 639 of file ~/.config/fish/functions/fisher.fish
    with parameter list '/Users/shane/.config/fisherman/gh'

in function '__fisher_update'
    called on line 257 of file ~/.config/fish/functions/fisher.fish
    with parameter list 'dickeyxxx/gh'

in function 'fisher'
    called on standard input
    with parameter list 'update dickeyxxx/gh'

Unsupported use of '='. In fish, please use 'set GH_BASE_DIR $GH_BASE_DIR:-$HOME/src'.
~/.config/fish/functions/gl.fish (line 1): GH_BASE_DIR=${GH_BASE_DIR:-$HOME/src}
                                           ^
from sourcing file ~/.config/fish/functions/gl.fish
    called on line 767 of file ~/.config/fish/functions/fisher.fish

in function '__fisher_plugin_enable'
    called on line 639 of file ~/.config/fish/functions/fisher.fish
    with parameter list '/Users/shane/.config/fisherman/gh'

in function '__fisher_update'
    called on line 257 of file ~/.config/fish/functions/fisher.fish
    with parameter list 'dickeyxxx/gh'

in function 'fisher'
    called on standard input
    with parameter list 'update dickeyxxx/gh'

Unsupported use of '='. In fish, please use 'set GH_BASE_DIR $GH_BASE_DIR:-$HOME/src'.
~/.config/fish/completions/gh.fish (line 1): GH_BASE_DIR=${GH_BASE_DIR:-$HOME/src}
                                             ^
from sourcing file ~/.config/fish/completions/gh.fish
    called on line 801 of file ~/.config/fish/functions/fisher.fish

in function '__fisher_plugin_enable'
    called on line 639 of file ~/.config/fish/functions/fisher.fish
    with parameter list '/Users/shane/.config/fisherman/gh'

in function '__fisher_update'
    called on line 257 of file ~/.config/fish/functions/fisher.fish
    with parameter list 'dickeyxxx/gh'

in function 'fisher'
    called on standard input
    with parameter list 'update dickeyxxx/gh'

Minor nitpick on directory selection

This line should not be able to have two dashes when I clone a thing:

$ gh roswell roswell
Cloning into '/home/l33t-hax0r/src//github.com/roswell/roswell'...

Reproduction:

set -x GH_BASE_DIR /home/ur-mum/src/ # leave final slash

This is a non-breaking bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.