Skip to content

Instantly share code, notes, and snippets.

@ciaran
Created July 22, 2009 15:14
Show Gist options
  • Save ciaran/152043 to your computer and use it in GitHub Desktop.
Save ciaran/152043 to your computer and use it in GitHub Desktop.
#!/bin/sh
SUBDIRECTORY_OK=Yes
. git-sh-setup
require_work_tree
ref_stash=refs/stash
COLOR_RED="\e[0;31m"
COLOR_GREEN="\e[32;40m"
COLOR_NONE="\e[0m"
have_stash () {
git rev-parse --verify $ref_stash >/dev/null 2>&1
}
have_stash || die 'No stash entries'
action_for_cmd () {
if [[ -n $1 ]]; then
for (( x=0 ; x < ${#commands[@]}; x++ )); do
[ $1 == "${commands[$x]}" ] && echo "${actions[$x]}" && break
done
fi
}
do_apply () { git stash apply $stash_ref; exit; }; help_apply () { echo "apply"; }
do_patch () { git stash show -p $stash_ref; }; help_patch () { echo "show patch"; }
do_pop () { git stash pop $stash_ref; exit; }; help_pop () { echo "pop"; }
do_drop () { git stash drop $stash_ref; }; help_drop () { echo "drop"; }
do_next () { stash_index=$(($stash_index+1)); }; help_next () { echo "view next stash entry"; }
do_quit () { exit; }; help_quit () { echo "quit"; }
do_help () {
for (( x=0 ; x < ${#commands[@]}; x++ )); do
echo "$COLOR_RED${commands[$x]} - $(help_${actions[$x]})$COLOR_NONE"
done
}
help_help () { echo "show this message"; }
commands=(a p P D n q ?)
actions=(apply patch pop drop next quit help)
stash_index=0
while [ $stash_index -le $(($(git log -g refs/stash --pretty=oneline|wc -l)-1)) ]; do
stash_ref=stash@{$stash_index}
git show --stat --pretty=short $stash_ref
echo "${COLOR_GREEN}What do you want to do? (one of: ${commands[*]})${COLOR_NONE} \c"
read
action=$(action_for_cmd $REPLY)
if [[ -n $action ]]; then
do_$action
else
echo "Invalid command" >&2
fi
have_stash || die 'No stash entries remaining'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment