Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Opens a local file on GitHub (macOS)
#!/usr/bin/env bash
set -e
FILE_DIR="$(dirname "${FILE_PATH}")"
cd ${FILE_DIR}
GIT_ROOT="$(git rev-parse --git-dir)/.."
REMOTES="$(git remote -v)"
GITHUB_REPO="$(sed 's/.*\(.*\).git.*/\1/' <<< "${REMOTES}" | head -1)"
GITHUB_PATH="$(/usr/local/bin/grealpath --relative-to="${GIT_ROOT}" "${FILE_PATH}")"
open "${GITHUB_URL}"

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.