编辑/etc/profile或者~/.bashrc 在行末添加如下内容
# 获取git当前分支 git_branch() { branch='' cd $PWD if [ -d '.git' ]; then output=`git describe --contains --all HEAD|tr -s ' '` if [ "$output" ]; then branch="(${output})" fi fi echo $branch } # linux IPADDRS=`/sbin/ifconfig | grep -P -o "((eth[w:]+)|(addr:[d.]+)|(lo[d:]*))" | perl -e '%face;foreach (<STDIN>){$int=$1 if (/((?:(?:eth)|(?:lo))[d:]*)/);$face{$int}=$1 if (/addr:([d.]+)/);};foreach $interf (sort keys %face){print "$interf = $face{$interf} " if ($interf !~ /^lo$/)}'` export PS1=" 33[1;34m[u@H]e[m 33[1;33m $IPADDRS e[m [ ] PWD => 33[1;35mwe[m 33[0;33m$(git_branch)e[m #>\$ " # windows msysgit # IPADDRS="eth0=`ipconfig |grep -i 'IPv4' |awk -F ': +' '{print $2}' |awk 'BEGIN{ORS=" "}{print $0}'`" # export PS1=" 33[1;34m[u@H]e[m 33[1;33m $IPADDRS e[m [ ] PWD => 33[1;35mwe[m 33[0;33m$(git_branch)e[m #># "
效果图: