1
我想混帐要求确认重置,所以我更新William Pursell's suggestion written here这样的:如何在使用TAB完成时防止git退出?
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 "[email protected]" || :
}
有了这个,如果我输错了命令,也不会从控制台退出,但如果我尝试使用它还是退出TAB完成。有没有办法来防止这种情况?
'set -e -u'通常是一个坏主意。 **尤其**在这里不合适,但在其他情况下也是如此。参见[BashFAQ#105](http://mywiki.wooledge.org/BashFAQ/105)和[BashFAQ#112](http://mywiki.wooledge.org/BashFAQ/112) - 和https:// www .in-ulm.de /〜mascheck/various/set-e/ –
顺便说一句,'[“$ resp”=“yes”]'是完全正确的。绝对不需要过时的'x $ resp'成语 - 它修复了只存在于[test]使用中的歧义,这些歧义被[现代POSIX标准]废弃(http://pubs.opengroup.org/onlinepubs/ 9699919799/utilities/test.html)(使用'-a'和'-o'在单个调用中组合多个不同的测试;请注意标准文档中标记语法过时的这些旁边的“[OB]”)没有接近任何角落案例的地方。 –