-
-
Save alexfu/f67cc41eb58ac0847fe8e06a4f381df4 to your computer and use it in GitHub Desktop.
GitHub Open File (GHOF)
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 | |
# Prints the GitHub URL of the chosen file. Requires fzf. | |
FILE=$1 | |
if [ -z "${FILE}" ] | |
then | |
FILE=$(fzf) | |
fi | |
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
ORIGIN_URL=$(git remote get-url origin) | |
ORIGIN_SHA=$(git rev-parse --short origin/$CURRENT_BRANCH_NAME) | |
ORIGIN_WEB_URL=https://$(echo $ORIGIN_URL | sed 's/[email protected]:/github.com\//g' | sed 's/\.git//g') | |
echo $ORIGIN_WEB_URL/blob/$ORIGIN_SHA/$FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
chmod +x ghof
)/usr/local/bin