PS1 env变量不适用于mac [英] PS1 env variable does not work on mac

查看:139
本文介绍了PS1 env变量不适用于mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本(不是我自己写的),它在我的命令提示符中显示了git branch / svn分支。有谁知道为什么这不适用于Mac?它在linux中完美运行。

I have a script(not written by myself) which shows the git branch/svn branch in my command prompt. Does anyone know why this would not work on mac? It works perfectly in linux.

https:/ /github.com/xumingming/dotfiles/blob/master/.ps1

# Display ps1 with colorful pwd and git status
# Acording to Jimmyxu .bashrc
# Modified by Ranmocy
# --

if type -P tput &>/dev/null && tput setaf 1 &>/dev/null; then
    color_prompt=yes
else
    color_prompt=
fi

__repo () {
    branch=$(type __git_ps1 &>/dev/null && __git_ps1 | sed -e "s/^ (//" -e "s/)$//")
    if [ "$branch" != "" ]; then
        vcs=git
    else
        branch=$(type -P hg &>/dev/null && hg branch 2>/dev/null)
        if [ "$branch" != "" ]; then
            vcs=hg
        elif [ -e .bzr ]; then
            vcs=bzr
        elif [ -e .svn ]; then
            vcs=svn
        else
            vcs=
        fi
    fi
    if [ "$vcs" != "" ]; then
        if [ "$branch" != "" ]; then
            repo=$vcs:$branch
        else
            repo=$vcs
        fi
        echo -n "($repo)"
    fi
    return 0
}

if [ "$color_prompt" = yes ]; then
# PS1='\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[33;40m\]$(__repo)\[\e[00m\]\$ '
    PS1='\[\e[01;32m\]\u\[\e[00m\]:\[\e[01;34m\]\W\[\e[33m\]$(__repo)\[\e[00m\]\$ '
else
    PS1='\u@\h:\w$(__repo)\$ '
fi
unset color_prompt

case "$TERM" in
xterm*|rxvt*)
  PS1="\[\e]0;\W\a\]$PS1"
  ;;
*)
  ;;
esac


推荐答案

Git的Mac OS X安装没有 __ git_ps1 包括在内。

Mac OS X installations of Git don't have __git_ps1 included.

使用:

Use:

alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"

作为替代品。

这篇关于PS1 env变量不适用于mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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