Last active
October 17, 2020 07:11
-
-
Save alexmacarthur/933a50c3e072baaf7b6ed18b94e0e873 to your computer and use it in GitHub Desktop.
Copies the last commit SHA to your clipboard.
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
# Copy the last commit in the current branch, or if passed as a parameter, a different branch. | |
# | |
# See the blog post documenting the surprisingly lengthly process of building this here: | |
# https://macarthur.me/posts/building-a-shell-function-to-copy-latest-commit-sha | |
function clc { | |
COLOR_GREEN="\033[0;32m" | |
COLOR_RESET="\033[0m" | |
[[ -z $1 ]] && BRANCH=$(git rev-parse --abbrev-ref HEAD) || BRANCH=$1 | |
LAST_COMMIT_SHA=$(git rev-parse $BRANCH | tail -n 1) | |
echo "$LAST_COMMIT_SHA" | tr -d '\n' | pbcopy | |
echo "Copied ${COLOR_GREEN}${LAST_COMMIT_SHA} ${COLOR_RESET}from ${BRANCH}." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment