sh Bash PS1设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Bash PS1设置相关的知识,希望对你有一定的参考价值。
# http://ezprompt.net/
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
}
# get current status of git repo
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
export PS1="\[\e[32m\]\A\[\e[m\] \[\e[34m\][\[\e[m\]\[\e[35m\]\u\[\e[m\]\[\e[32m\]@\[\e[m\]\[\e[35m\]\h\[\e[m\]\[\e[34m\]]\[\e[m\] \[\e[31m\]\W\[\e[m\]\[\e[34m\]\`parse_git_branch\`\[\e[m\] \[\e[33m\]\\$\[\e[m\] "
以上是关于sh Bash PS1设置的主要内容,如果未能解决你的问题,请参考以下文章
Centos7命令行提示符设置
修改bash终端命令行颜色
oh-my-zsh终端用户名设置(PS1)
在 Linux 终端中自定义 Bash 配色和提示内容
Spark环境常用配置(profile)
Bash之PS1配置