Skip to content

Instantly share code, notes, and snippets.

@wrecklass
Created June 28, 2019 16:37
Show Gist options
  • Save wrecklass/8fee9f4e7819a680ada65030d04b024b to your computer and use it in GitHub Desktop.
Save wrecklass/8fee9f4e7819a680ada65030d04b024b to your computer and use it in GitHub Desktop.
Open Stash based git repo in Browser from command line
#!/bin/bash
STASH_SERVER="stash.dev-charter.net"
remotes="$(git remotes -v 2> /dev/null | tail -n 1)"
if [[ -n "${remotes}" ]];then
SEP="7999"
if [[ "$remotes" =~ "https:" ]];then
SEP="scm"
fi
# Safely ignore this shellcheck as the sed is to complex for a simple variable replacement
# shellcheck disable=SC2001
open "$(echo "$remotes" | sed -e "s#.*${SEP}/\(.*\)/\(.*\).git.*#https://${STASH_SERVER}/stash/projects/\1/repos/\2/browse#")"
else
printf "Error: %s does not appear to be in a git repository\n" "$(basename "${PWD}")"
fi
@wrecklass
Copy link
Author

Handy script to open the current git repo in the default browser. To use:

Place the script somewhere in your $PATH
In the terminal, cd to a git repo or any of its subdirectories.
run the script browseStash

Your default browser should open a new tab (or window depending on your settings) with the stash repo you were looking at. Works if the remote is https or ssh based.

Handy for creating a PR after doing a push on a new branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment