Skip to content

Instantly share code, notes, and snippets.

@alexmacarthur
Last active October 17, 2020 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexmacarthur/933a50c3e072baaf7b6ed18b94e0e873 to your computer and use it in GitHub Desktop.
Save alexmacarthur/933a50c3e072baaf7b6ed18b94e0e873 to your computer and use it in GitHub Desktop.
Copies the last commit SHA to your clipboard.
# 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