Skip to content

Instantly share code, notes, and snippets.

@georgelesica-wf
Last active April 20, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgelesica-wf/75aac8373b405791d42e04d955123399 to your computer and use it in GitHub Desktop.
Save georgelesica-wf/75aac8373b405791d42e04d955123399 to your computer and use it in GitHub Desktop.
Little shell script for automating switching between different Git tags in a presentation.
#!/usr/bin/env bash
set -e
CACHE_FILE="$HOME/.tags-cache"
if [ -f "$CACHE_FILE" ]; then
CURRENT_TAG=$(<"$CACHE_FILE")
else
unset CURRENT_TAG
fi
if [ -z ${TAG_PREFIX+x} ]; then
TAG_PREFIX=""
fi
function checktag() {
if [ -z ${CURRENT_TAG+x} ]; then
echo "No tag currently set. Use 'jump'."
exit 1
fi
}
function jumptag() {
git reset --hard
git checkout "$TAG_PREFIX$CURRENT_TAG"
git reset --soft HEAD^
}
function savetag() {
touch "$CACHE_FILE"
echo "$CURRENT_TAG" > "$CACHE_FILE"
}
case "$1" in
next | n)
checktag
let CURRENT_TAG+=1
jumptag
savetag
;;
prev | p)
checktag
let CURRENT_TAG+=-1
jumptag
savetag
;;
jump | j)
CURRENT_TAG="$2"
jumptag
savetag
;;
kill | k)
rm "$CACHE_FILE"
;;
*)
echo "Usage: ./tags.sh CMD [DEST]"
echo "where CMD can be one of"
echo " next"
echo " prev"
echo " jump DEST"
echo " kill"
echo "and DEST is a tag number."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment