-
-
Save asannikov/ac26e47bbe429f3a6f54f39b4281920e to your computer and use it in GitHub Desktop.
output and open GitHub URL for current/pointed directory/file
This file contains hidden or 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
#!/usr/bin/env bash | |
BASEREPO="$(git remote -v | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/git@/http:\/\//' -e's/\.git$//' | sed -E 's/(\/\/[^:]*):/\1\//')" | |
BASEREPO="${BASEREPO}" | |
CURRENTBRANCH="$(git branch | grep \* | cut -d ' ' -f2)" | |
CURRENTBRANCH="${CURRENTBRANCH}" | |
BASEPATH="$(git rev-parse --show-toplevel)" | |
BASEPATH="${BASEPATH}" | |
ABSOLUTEPATH="$(pwd)" | |
ABSOLUTEPATH="${ABSOLUTEPATH}" | |
RELATIVEPATH=${ABSOLUTEPATH#"$BASEPATH"} | |
RELATIVEPATH=${RELATIVEPATH%"$BASEPATH"} | |
if [ -n $1 ] | |
then | |
FILE=$1 | |
FILE="/${FILE}" | |
fi | |
echo "${BASEREPO}/tree/${CURRENTBRANCH}${RELATIVEPATH}${FILE}" | |
open "${BASEREPO}/tree/${CURRENTBRANCH}${RELATIVEPATH}${FILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment