Skip to content

Instantly share code, notes, and snippets.

@g1eb
Created January 11, 2015 04:59
Show Gist options
  • Save g1eb/89a380f88bc4ce982f07 to your computer and use it in GitHub Desktop.
Save g1eb/89a380f88bc4ce982f07 to your computer and use it in GitHub Desktop.
# Git wrapper with [y/N] prompt
g () {
out="$(script -q /dev/null command git "$@" 2>&1)"; out="${out//$'\r'}"
echo "$out"
if [[ "$out" == *"Did you mean this?"* ]]; then
cmd="${out##*$'\n'}"; cmd="${cmd//$'\t'}"
tput bold; read -r -p "[y/N]? " < /dev/tty res
if [[ $res =~ ^$|^([yY]|[yY][eE][sS])$ ]]; then
echo; command git $cmd
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment