当我使用TAB完成时如何防止git退出?

时间:2017-07-25 13:19:46

标签: git bash

我希望git要求确认重置,因此我更新了William Pursell's suggestion written here,如下所示:

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"
        else                
            echo "NOT Resetting"
            return 0
        fi
    fi
fi
command git "$@" || :
}

如果我输错命令,它将不会从控制台退出,但如果我尝试使用TAB完成,它仍然会退出。有办法防止这种情况吗?

1 个答案:

答案 0 :(得分:1)

删除第set -e -u行。这些设置对于shell会话是全局的,而不是函数本地的,并且它们与shell完成函数冲突,这些函数不受未定义变量(set -u)的影响。由于您的功能写得很好,因此您既不需要set -e也不需要set -u