例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
当前回答
只需在.bashrc中输入下面的内容,然后重新启动终端。导航到Git repo以查看提示符中的路径。
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '
其他回答
在我的ubuntu上有一个文件安装在这里:
source /etc/bash_completion.d/git-prompt
您可以按照链接进入/usr/lib/git-core文件夹。你可以在那里找到一个指令,如何设置PS1或使用__git_ps1
在Ubuntu 22.04中,只需在.bashrc或.zshrc后面添加这一行即可
source /etc/bash_completion.d/git-prompt
窗户
我最终在Windows 10命令行(cmd)上的工作原理:
安装叮当声 git-autocomplete副本。lua文件到C:\Users\<username>\AppData\local\clink目录 重新启动Windows
参见https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
您只需要获取完成脚本的源代码
Mac M1
对于那些使用Mac M1环境的用户,我可以通过自制软件进行安装:
酿造安装bash-completion
然后添加到我的~/。Bash_profile或~/。Bashrc(不管你用什么):
[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"
您可能需要更新版本号(1.3_3)。你只需要在那个目录中查找即可。我很想知道有没有更好的办法。