在提示中显示git分支名称在屏幕上不起作用 [英] Displaying git branch name in prompt does not work in screen

查看:207
本文介绍了在提示中显示git分支名称在屏幕上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的.bashrc文件,如下所示:
$ b

I updated my .bashrc file as follows:

PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$'

它的作品只是找到,我可以在提示中看到我的分支名称。然而,当我运行屏幕,我得到

It works just find and I can see my branch name in the prompt. However,when I run "screen" , I get


- bash:__git_ps1:找不到命令

"-bash: __git_ps1: command not found"

可能是什么原因?

What can be the reason for this?

推荐答案

< a href =http://velomatrix.net/2011/01/04/show-the-current-git-branch-in-your-bash-prompt/>这篇博文解释说你必须添加行 source /etc/bash_completion.d/git ,然后才能使用 __ git_ps1

This blog post explains that you have to add the line source /etc/bash_completion.d/git before you can use __git_ps1.

以下是完整的示例:

Here is the full example:

source /etc/bash_completion.d/git  
export PS1='\w$(__git_ps1 "(%s)") > '

这也支持分行的自动完成。

This also enables auto completion for branches.

使用该格式,您的提示类似于(不着色):

Using that formatting, your prompt will resemble (without colouring):

~/my-repo(master) > 

这篇关于在提示中显示git分支名称在屏幕上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆