Bash script to dynamically open web pages straight from the terminal

Say you work at Microsoft, and you work on a number of repositories under https://github.com/microsoft.

For eg:

All of these URLs share the https://github.com/microsoft/ pattern followed by the name of the project (eg: vstest).

The script

Here's a bash script that will let you open specific repositories on Github straight from your terminal by passing in the name of the repo as an argument.

function goto() { URL="https://github.com/microsoft" URL+=$1 open $URL }

We can go a step further and make it easy to open up either pull requests, issues or tags within these repos by passing in a second argument, like so:

function goto() { URL="https://github.com/microsoft" URL+=$1 if [ "$2" = "-p" ]; then URL+="/pulls" elif [ "$2" = "-i" ]; then URL+="/issues" elif [ "$2" = "-t" ]; then URL+="/tags" fi open $URL }

Usage

Once you've added this function to your .bashrc file (or your .zshrc file), you should be able to refresh and use the script like so:

goto vscode -p

This will open up a browser window (if none are open) and go to the vscode project's pull requests page.

This is especially useful if you navigate between lots of microservices and need to go check something quickly.

The source code for this website can be found here under an MIT license