Bash提示符显示Git分支

今天看Railscasts,才发现可以在命令行显示git分支,找到2篇帖子,把他们融合了一下:

# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!

# visit https://wiki.archlinux.org/index.php/Color_Bash_Prompt for more color.

WHITE="\[\033[0m\]"
YELLOW="\[\033[0;33m\]"
export PS1="\w:$YELLOW\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)$WHITE\$ "

This entry was posted in 其它. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Jinleileiking

    为什么不用zsh 

  • Makestory

     我用的是这样的  makestory@laptop ~/igeey[home*]$ 
    有*号说明有改动未提交,速度还可以。function parse_git_dirty {
      [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo “*”
    }
    function parse_git_branch {
      git branch –no-color 2> /dev/null | sed -e ‘/^[^*]/d’ -e “s/* (.*)/[1$(parse_git_dirty)]/”
    }
    export PS1=’u@h [33[1;33m]w[33[0m]$(parse_git_branch)$ ‘

  • Anonymous

    你这个高级 

  • Eric Lo

    可以试试这个zsh插件OH MY ZSHELL! https://github.com/robbyrussell/oh-my-zsh

  • Anonymous

    哇,这个太赞了

无觅相关文章插件,快速提升流量