Last active
March 21, 2018 22:11
-
-
Save chrisballinger/f6122c326a340a1ab6d905d2ab24b478 to your computer and use it in GitHub Desktop.
Opens a local file on GitHub (macOS)
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
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
brew install coreutils