Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.