Skip to content

Instantly share code, notes, and snippets.

@dyokomizo
Forked from mbbx6spp/README.md
Created December 6, 2011 08:46
Show Gist options
  • Save dyokomizo/1437420 to your computer and use it in GitHub Desktop.
Save dyokomizo/1437420 to your computer and use it in GitHub Desktop.
Idea for getting GitHub URLs for various needs

GitHub (Bash) Shell URLs

Local Shell setup

This is an environment file to source upon shell startup (via .bashrc/.bash_profile or your shell's corresponding file). If your shell isn't Bash you will likely need to port the functions to your shell's syntax.

Setup your local clone of a GitHub repo

When inside your local Git clone of a Github repo you need to do the following (only once per repo):

git config --add github.repo "user/repo-name"

So in this case you are saying your Github repo is found at https://github.com/user/repo-name.

General Shell usage

When inside your local repo you can do the following:

ghrepourl # => https://github.com/user/repo-name
ghbranchurl # => https://github.com/user/repo-name/branches/
ghbranchurl my-feature-branch # => https://github.com/user/repo-name/branches/my-feature-branch
ghtagsurl # => https://github.com/user/repo-name/tags
ghcompurl SHA1 SHA2 # => https://github.com/user/repo-name/compare/SHA1...SHA2
ghcommiturl SHA1 # => https://github.com/user/repo-name/commit/SHA1

Usage with Tig

When running tig in your local clone, if you have already added the following to your ${HOME}/.tigrc file then you can do the following:

bind diff O !open $(ghcommiturl %(commit))
bind main O !open $(ghrepourl)
bind branch O !open $(ghbranchurl %(branch))
#!/usr/bin/env bash
function ghRepo() { echo $(git config --get github.repo); }
function ghRepoUrl() {
echo "https://github.com/$(ghRepo)";
}
function ghBranchUrl() {
local branch="$1";
echo "$(ghRepoUrl)/branches/${branch}";
}
function ghTagsUrl() {
echo "$(ghRepoUrl)/tags";
}
function ghCompareUrl() {
local first="$1";
local last="$2";
echo "$(ghRepoUrl)/compare/${first}...${last}";
}
function ghCommitUrl() {
local commit="$1";
echo "$(ghRepoUrl)/commit/${commit}";
}
alias ghrepourl="ghRepoUrl"
alias ghcompurl="ghCompareUrl"
alias ghbranchurl="ghBranchUrl"
alias ghtagsurl="ghTagsUrl"
alias ghcommiturl="ghCommitUrl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment