Skip to content

Instantly share code, notes, and snippets.

@sompylasar
Created August 22, 2018 04:18
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 sompylasar/2de2f3292646250c297637fece4c0fb7 to your computer and use it in GitHub Desktop.
Save sompylasar/2de2f3292646250c297637fece4c0fb7 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
REPO_PATH=$1
SHA=$2
if [[ ! -d "${REPO_PATH}" ]]; then
exit -1
fi
if [[ -z "${SHA}" ]]; then
exit -2
fi
REPO_GITHUB_URL=`cd "${REPO_PATH}" && git remote get-url origin`
REPO_GITHUB_URL_SSH_PREFIX="git@github.com:"
REPO_GITHUB_URL_SSH_SUFFIX=".git"
REPO_GITHUB_URL_HTTPS_PREFIX="https://github.com/"
REPO_GITHUB_PATH=${REPO_GITHUB_URL}
REPO_GITHUB_PATH=${REPO_GITHUB_PATH/#$REPO_GITHUB_URL_SSH_PREFIX}
REPO_GITHUB_PATH=${REPO_GITHUB_PATH/%$REPO_GITHUB_URL_SSH_SUFFIX}
REPO_GITHUB_PATH=${REPO_GITHUB_PATH/#$REPO_GITHUB_URL_HTTPS_PREFIX}
URL="https://github.com/${REPO_GITHUB_PATH}/commit/${SHA}"
echo "${URL}"
open "${URL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment