Skip to content

Instantly share code, notes, and snippets.

@alexfu
Last active August 22, 2022 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexfu/f67cc41eb58ac0847fe8e06a4f381df4 to your computer and use it in GitHub Desktop.
Save alexfu/f67cc41eb58ac0847fe8e06a4f381df4 to your computer and use it in GitHub Desktop.
GitHub Open File (GHOF)
#!/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/git@github.com:/github.com\//g' | sed 's/\.git//g')
echo $ORIGIN_WEB_URL/blob/$ORIGIN_SHA/$FILE
@alexfu
Copy link
Author

alexfu commented Aug 22, 2022

Instructions:

  1. Download script
  2. Ensure script is executable (chmod +x ghof)
  3. Copy script to a global binary folder like /usr/local/bin

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