我上次使用它是在 2016 年,当时使用的是旧版本的 Mac OS。我现在使用的是10.3.1。
# This file is sourced by bash for login shells. The following line
# runs your .bashrc and is recommended by the bash info pages.
if [[ -f ~/.bashrc ]] ; then
. ~/.bashrc
fi
# Get current git branch
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 repository's current status
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
}
# Custom command line
export PS1="\n\[\e[1m\e[38;5;57m\]\w \[\e[0m\e[38;5;66m\]\`parse_git_branch\`\n\[\e[38;5;45m\]\$(date +%H:%M:%S) \[\e[38;5;57m\]» \[\e[38;5;15m\]"
# Custom ls colours
export LS_COLORS=$LS_COLORS:'di=1;32:'
这是它显示的内容
\n\[\e[1m\e[38;5;57m\]\w \[\e[0m\e[38;5;66m\]`parse_git_branch`\n\[\e[38;5;45m\]$(date +:samuels-mbp.lan:) \[\e[38;5;57m\]» \[\e[38;5;15m\]