Created
January 11, 2018 12:09
-
-
Save AlicanC/471210230efdc9339b465ee6ce31a3e7 to your computer and use it in GitHub Desktop.
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
# 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