Skip to content

Instantly share code, notes, and snippets.

@AlicanC
Created January 11, 2018 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlicanC/471210230efdc9339b465ee6ce31a3e7 to your computer and use it in GitHub Desktop.
Save AlicanC/471210230efdc9339b465ee6ce31a3e7 to your computer and use it in GitHub Desktop.
# Helpers
ask() {
# http://djm.me/ask
local prompt default REPLY
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read REPLY </dev/tty
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
# Aliases
function .gitClean() {
git clean -xfdn -e __shizzle/ :/
if ask "Go?" N; then
git clean -xfd -e __shizzle/ :/
echo "Cleaned."
else
echo "Bailed."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment