Linux的PS1 - 显示屏分会名存实亡内混帐回购协议 [英] linux PS1 - display branch name only inside a git repo

查看:118
本文介绍了Linux的PS1 - 显示屏分会名存实亡内混帐回购协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索网后,我发现有一个可以用PS1显示如下

After searching the net, I found that one can display the git branch name with the PS1 with below

PS1="$(__git_ps1 ) "

虽然这工作正常,并显示PS1提示分支名称。但它显示的地方,我曾经浏览之外,也混帐签出的回购。

While this is working fine, and it display the branch name in PS1 prompt. But it is displayed where-ever I navigate, even outside the git-checked-out-repo.

我想只显示,如果我是一个git的跟踪文件夹/回购下的分支名。任何方式实现这一目标?搜索SO和净利润没有弹出有用的链接,在这方面。

I would like to display the branch name only if I am under a git tracked folder/repo. Any way to achieve this? Searching SO and net didn't pop-up helpful links in this respect.

推荐答案

您需要推迟 $(__ git_ps1)直到 PS1 <执行/ code>实际显示。使用单引号:

You need to defer execution of $(__git_ps1) until PS1 is actually displayed. Use single quotes:

PS1='$(__git_ps1)'

这篇关于Linux的PS1 - 显示屏分会名存实亡内混帐回购协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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