[英]git completion broken by bash profile alias 'test'
I had an alias in my bash profile like this:我的 bash 配置文件中有一个别名,如下所示:
alias test='cd /Usr/work/dir/test'
every time I would try to use bash completion for git in a terminal it would:每次我尝试在终端中使用 bash 完成 git 时,它都会:
As soon as I removed that alias bash completion for git works fine.一旦我删除别名 bash 完成 git 工作正常。 Why's that?为什么?
git version 2.26.2 git 版本 2.26.2
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19) Copyright (C) 2007 Free Software Foundation, Inc. GNU bash,版本 3.2.57(1)-release (x86_64-apple-darwin19) 版权所有 (C) 2007 Free Software Foundation, Inc.
test
is a built-in command, and creating an alias named test
shadows it, which could lead to unforeseen issues. test
是一个内置命令,创建一个名为test
的别名会隐藏它,这可能会导致无法预料的问题。 Pick a different name.选择一个不同的名称。
alias goto_test='cd /Usr/work/dir/test'
However, this is probably the least desirable solution.然而,这可能是最不理想的解决方案。 First, consider using a function instead:首先,考虑使用 function 代替:
goto_test () {
cd /Usr/work/dir/test
}
Second, you can add /Usr/work/dir
to your CDPATH
variable, so that you can quickly switch to any subdirectory without having to use the entire path.其次,您可以将/Usr/work/dir
添加到您的CDPATH
变量中,这样您就可以快速切换到任何子目录,而无需使用整个路径。
$ CDPATH=/Usr/work/dir
$ cd test
/Usr/Work/dir
$ pwd
/Usr/Work/dir/test
This saves you from having to define multiple aliases or functions if there are several directories you might commonly switch to.如果您可能经常切换到多个目录,这使您不必定义多个别名或函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.