如何在PS1与其他输出显示混帐分支? [英] How to display git branch in PS1 with other output?

查看:104
本文介绍了如何在PS1与其他输出显示混帐分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,如果我在一个git仓库中的PS1只显示该分支名
<一href=\"http://stackoverflow.com/questions/31970203/linux-ps1-display-branch-name-only-inside-a-git-repo\">linux PS1 - 显示屏分会名存实亡内混帐回购协议,但我不能够得到它与我早先的PS1,这是集成

  PS1 =[\\ D {%F} \\ @] \\ U / \\ W $

这显示,日期时间+用户名

  [2015年8月20日下午11点38分] MTK

我试过

  PS1 =[\\ D {%F} \\ @] \\ U / \\ W $(__ git_ps1)$

不过,我得到的错误

  __ git_ps1:命令未找到
&LT;空PS1&GT;

什么办法让git的分支名与早期的细节,用于输出我PS1一起?

编辑:
我也试过

  PS1 =[\\ D {%F} \\ @] \\ U / \\ W'$(__ git_ps1)$

不过,这给空行情始终,甚至内部的混帐回购协议。

的问题是从一个不同的。我是为了显示时间和日期+ git的分支(如果回购内部)。


解决方案

  PS1 =[\\ D {%F} \\ @] \\ U / \\ W \\ $(__ git_ps1)$ 

  PS1 ='[\\ D {%F} \\ @] \\ U / \\ W $(__ git_ps1)$'

您必须逃离 $ ,以便在每次执行,而不是只有一次。您可以使用单引号或逃避它这样做的一个 \\

I got to display just the branch name in the PS1 if I am in a git repo linux PS1 - display branch name only inside a git repo, but I am not able to get it integrated with my earlier PS1, which is

 PS1="[\D{%F} \@] \u /\W $ "

this displays, datetime + username

 [2015-08-20 11:38 PM] mtk 

I tried

PS1="[\D{%F} \@] \u /\W $(__git_ps1) $ "

but, i get error

__git_ps1: command not found
<empty PS1>

Any way to get git branch name along with earlier details that my PS1 used to output?

EDIT: I also tried

 PS1="[\D{%F} \@] \u /\W '$(__git_ps1)' $ "

but, this gives empty quotes always, even inside a git repo.

The question is different from that one. I was to display time and date + git branch (if its inside a repo).

解决方案

PS1="[\D{%F} \@] \u /\W \$(__git_ps1) $ "

or

PS1='[\D{%F} \@] \u /\W $(__git_ps1) $ '

You must escape the $ in order to be executed each time, not only once. You can do so by using single quotes or escaping it with a \.

这篇关于如何在PS1与其他输出显示混帐分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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