Skip to content

Instantly share code, notes, and snippets.

@willdages
Last active September 3, 2020 21:46
Show Gist options
  • Save willdages/3e47d8f724c36a54a28e to your computer and use it in GitHub Desktop.
Save willdages/3e47d8f724c36a54a28e to your computer and use it in GitHub Desktop.
Github Shell Script

GitHub Shell Script

Installation

Make sure the shell script is executable:

$ chmod +x /path/to/github.sh

In your ~/.bash_profile add an alias for the script:

alias github='~/path/to/github.sh'

Restart your terminal.

Usage

To open the GitHub page for your repo:

$ github

To open a specific GitHub subpage for your repo, just add the identifier (url) of the page. For Pull Requests, it would look like this:

$ github pulls

For the wiki:

$ github wiki
#!/bin/bash
remotes=$(git remote -v)
if [ "$?" != "0" ]; then
echo "No remotes found. Please try running this command again inside of a repository." 1>&2
exit 1
fi
re="https?:\/\/[^ ]+"
url=$(if [[ $remotes =~ $re ]]; then
echo ${BASH_REMATCH[0]}
fi)
len=${#url}-4
url="${url:0:$len}"
open "$url/$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment