Bence Ács Bence Ács - 1 year ago 50
Git Question

How to prevent git from quitting when I use TAB completion?

I want git to require confirmation for resetting, so I updated William Pursell's suggestion written here like this:

git() {
set -e -u
if [ $# -ge 2 ]; then
if [ "x$1" = "xreset" -a "x$2" = "x--hard" ]; then
echo "Are you sure? (Type 'yes')"
read resp || return $?
if [ "x$resp" = "xyes" ]; then
echo "Resetting"
echo "NOT Resetting"
return 0
command git "[email protected]" || :

With this it won't quit from the console if I mistype the command, but it still quits if I try to use TAB completion. Is there a way to prevent this?

Answer Source

Remove the line set -e -u. Those settings are global to your shell session, not local to your function, and they conflict with the shell completion functions which are not immune to undefined variables (set -u). And since your function is well written, you need neither set -e nor set -u.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download