有没有办法在 Mac 的终端提示中添加当前工作目录/当前 git 存储库/分支
第一次海报。
这在本周的工作对话中出现了......
有没有办法,当你远程连接到 git 时,你可以在终端提示符中显示当前工作目录/当前 git repo/branch ?
显然,有针对 Linux 用户的 linux/vim 脚本,我想将这种 shell 脚本添加到我的配置文件中。
目前我正在使用此页面中的一些信息 http://sos.blog-city.com/mac_os_x__bash_customize_your_terminal_prompt_a_little_color .htm 在本地处理其中一些信息。
提前致谢。
first time poster.
This came up in conversation at work this week...
Is there a way, when you connect to git remotely that you can get display current working directory/current git repo/branch in your terminal prompt?
Apparently, there are linux/vim scripts that exist for linux users, and I'd like to add this sort of shell script to my profile.
Currently I'm using some info from this page http://sos.blog-city.com/mac_os_x__bash_customize_your_terminal_prompt_a_little_color.htm to address some of this info locally.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
获取 git 完成脚本的副本。你可以从 git 本身获取它,或者如果你有一个方便的 Linux 盒子,你甚至可以从那里复制它(它可能是
/etc/bash_completion.d/git
)。然后,安排它通过 bash“获取”。您可以通过在.bashrc
中添加类似的内容来完成此操作:(假设您在 Mac 上将文件命名为
/usr/local/git-completion
)。最后,您需要调整提示。另外,在您的
.bashrc
中,添加如下内容:这是一篇博客文章(不是我写的),更详细地讨论了此问题(以及其他一些相关内容):http://blog.bit Fluent.com/post/27983389/git-utilities-you-cant-live-without
Get a copy of the git completion script. You can get this from git itself, or if you have a Linux box handy you could even just copy it from there (it'll probably be
/etc/bash_completion.d/git
). Then, arrange for this to get "sourced" by bash. You can do this by adding something like this to your.bashrc
:(assuming you named the file
/usr/local/git-completion
on your Mac).Finally, you'll want to adjust your prompt. Also in your
.bashrc
, add something like:Here's a blog post (not by me) that talks about this (and some other related stuff) in more detail: http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without
好的,在你为我指明正确的方向后,我尝试了这个,我的谷歌搜索得到了更精确的结果。
很多人都指向您与我分享的帖子,如下所示:https://superuser.com/questions/31744/how-to-get-git-completion-bash-to-work-on-mac-os-x 但我发现其他一些像这样的珠宝,我没有使用,但信息丰富:jeetworks.org/node/10,jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/。
我需要一些关于安装 git.completion 的不同指导,因为我使用在这里找到的自制软件: https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion 其中涵盖了几种安装方法。
最后,我的 bash/终端有点迟钝,所以在我使用这些指令之前,我按照这些说明升级到了最新的 bash:milkbox.net/brace_completion_snow_leopard_upgrading_bash/ 并获得了一些很大的速度改进。
我最终不得不非常仔细地重建我的配置文件脚本,但有线索和错误(因为 Bash 3 和 4 之间的差异,以及一些语法错误)——现在它看起来很棒,并且可以完成工作。
再次感谢。
对于上述网站的安全限制,我们深表歉意,限制我(因为我是新手)只能使用 2 个链接来打击垃圾邮件。
OK, I experimented with this after you pointed me in the right direction, my google searches got more refined results.
A lot of people point to the post you shared with me, like here: https://superuser.com/questions/31744/how-to-get-git-completion-bash-to-work-on-mac-os-x but I found some other jewels like these, which I didn't use but were informative: jeetworks.org/node/10 , jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ .
I needed some different guidance on installing git.completion because I use homebrew which I found here: https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion which covers several ways to install it.
Finally, my bash/terminal has been a bit pokey so I upgraded to the latest bash with these instructions before I meshed with any of this: milkbox.net/brace_completion_snow_leopard_upgrading_bash/ and got some great speed improvement.
I ended up having to rebuild my profile script very carefully but with trail and error (because of differences between Bash 3 and 4, and some syntax errors)- now it looks great, and does the job.
Thanks again.
Sorry about above the security restraints of the site, restrict me (since I'm a newb) to 2 links to combat spam.
您只需要 2 个步骤即可完成。
步骤1:
在您喜欢的编辑器中打开~/.bash_profile并将以下内容添加到底部。
对我来说就像
Step.2:
将以下内容添加到底部。
完毕!
PS:
如果你想让你的终端色彩缤纷,请尝试以下内容。
You just need 2 steps to do it.
Step.1:
Open ~/.bash_profile in your favorite editor and add the following content to the bottom.
For me it is like
Step.2:
Add the following content to the bottom.
Done!
P.s:
If you want your terminal colorful, try the following content.
在 shell 提示符中获取 git 分支/状态信息的另一种选择是使用 powerline-shell。
您可以在这个屏幕截图中看到它的样子:
![在此处输入图像描述](https://i.sstatic.net/rO2Bu.png)
洋红色/绿色条是当前分支名称。它的颜色表示工作目录是否干净。当存在未跟踪的文件或有要从上游远程拉取/推送到上游远程的提交时,还会出现标记。
Powerline-shell 与 bash、zsh 和 Fish 兼容。
Another option to get git branch/status info in your shell prompt is to use powerline-shell.
You can see what this looks like in this screenshot:
![enter image description here](https://i.sstatic.net/rO2Bu.png)
The magenta/green bar is the current branch name. Its color indicates whether the working directory is clean. There are also markers that appear when there are untracked files, or when there are commits to be pulled-from/pushed-to the upstream remote.
Powerline-shell is compatible with bash, zsh, and fish.