Skip to content

Instantly share code, notes, and snippets.

@natemoo-re
Created September 25, 2024 18:26
Show Gist options
  • Save natemoo-re/e8f6d1ee6623961da50d22a5e2bb0c90 to your computer and use it in GitHub Desktop.
Save natemoo-re/e8f6d1ee6623961da50d22a5e2bb0c90 to your computer and use it in GitHub Desktop.
Copy last SHA
sha() {
value=$(git rev-parse --short HEAD 2>/dev/null)
if [ $? -ne 0 ]; then
echo "\e[31m▲ Unable to detect latest commit!\e[0m\n\e[2m Is\e[0m \e[36m$(basename "$PWD")\e[0m \e[2ma git repository?\e[0m" >&2
return
fi
# or `xclip -selection clipboard` on unix
echo $value | pbcopy
echo "\e[32m●\e[0m Copied \e[36m$value\e[0m to clipboard!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment