-
-
Save Vladmel1234/914622e7431635fef306f2f332e4c524 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}." | |
} | |
function plc { | |
COLOR_GREEN="\033[0;32m" | |
COLOR_CYAN="\033[0;36m" | |
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 commmit sha in branch ${COLOR_CYAN}${BRANCH}${COLOR_RESET} is ${COLOR_GREEN}${LAST_COMMIT_SHA} ${COLOR_RESET}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment