提示中的Git分支名称 [英] Git branch name in prompt

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

问题描述

我能够在shell提示符下显示git分支名称。但是,无论何时我使用屏幕,我都会收到

pre $ b $ c $ bash:parse_git_branch:找不到命令

和git分支未显示。
请帮助我在屏幕会话中获得此信息。



我在.bash_profile中有以下内容。

  parse_git_branch(){
git branch 2> / dev / null | sed -e'/ ^ [^ *] / d'-e's / * \(。* \)/(\ 1)/
}

export PS1 = [\W\ $(parse_git_branch)] $

我没有 .git-completion.bash



系统规格:


  • 操作系统:OSX 10.8.4

  • 终端& iTerm2

  • 屏幕版本:4.00.03(FAU)23-Oct-06


解决方案打开终端时, .bash_profile 会被执行,因此定义 PS1 。然后执行屏幕,然后屏幕读取环境变量 PS1 ,其中包含对 parse_git_branch 的调用并尝试解析它。但是,由于屏幕没有执行 .bash_profile ,因此未在屏幕内定义 parse_git_branch 函数。



PS1 的定义移动到 .bashrc ,因为屏幕和iTerm执行它。


I am able to show the git branch name in the shell prompt. But whenever I am using screen I am getting

bash: parse_git_branch: command not found

and git branch is not shown. Please help me get this in the screen sessions also.

I have following in my .bash_profile.

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/
}

export PS1="[\W\$(parse_git_branch)]$ "

I don't have .git-completion.bash

System specs:

  • OS: OSX 10.8.4
  • Terminal & iTerm2
  • Screen version: 4.00.03 (FAU) 23-Oct-06

解决方案

When you open your terminal, .bash_profile is executed and therefore PS1 is defined. Then you execute screen, and screen reads the environment variable PS1 which includes a call to parse_git_branch and tries to parse it. But, since screen didn't execute .bash_profile the function parse_git_branch is not defined inside screen.

Move the definition of PS1 to .bashrc because both, screen and iTerm execute it.

这篇关于提示中的Git分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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