Skip to content

Instantly share code, notes, and snippets.

@chrisballinger
Last active March 21, 2018 22:11
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 chrisballinger/f6122c326a340a1ab6d905d2ab24b478 to your computer and use it in GitHub Desktop.
Save chrisballinger/f6122c326a340a1ab6d905d2ab24b478 to your computer and use it in GitHub Desktop.
Opens a local file on GitHub (macOS)
#!/usr/bin/env bash
set -e
FILE_PATH="${1}"
FILE_DIR="$(dirname "${FILE_PATH}")"
cd ${FILE_DIR}
GIT_ROOT="$(git rev-parse --git-dir)/.."
REMOTES="$(git remote -v)"
GITHUB_REPO="$(sed 's/.*github.com:\(.*\).git.*/\1/' <<< "${REMOTES}" | head -1)"
GITHUB_PATH="$(/usr/local/bin/grealpath --relative-to="${GIT_ROOT}" "${FILE_PATH}")"
GITHUB_URL="https://github.com/${GITHUB_REPO}/blob/develop/${GITHUB_PATH}"
open "${GITHUB_URL}"
@chrisballinger
Copy link
Author

Requires brew install coreutils

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