Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Mar 21, 2018

Requires brew install coreutils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.