Created
June 28, 2019 16:37
-
-
Save wrecklass/8fee9f4e7819a680ada65030d04b024b to your computer and use it in GitHub Desktop.
Open Stash based git repo in Browser from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
orssh
based.Handy for creating a PR after doing a push on a new branch.