如果我在 git repo 的命令行中运行它
git status 2> /dev/null | grep -iw 'modified'
我得到的输出
# modified: .rvmrc
所以我的假设是,如果我将它插入到 if 语句中,我将得到正确的执行代码行
但是当我创建函数作为 .bash_profile 的一部分时,这是我拥有的代码:
## Prompt ##
path="$white\w$reset"
folder_name="$white\W$reset"
git_branch="\$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/$red(\1)$reset/')"
rvm="$green(\$(~/.rvm/bin/rvm-prompt i v p))$reset"
# Checks if working tree is dirty
function _git_st {
if [[ $(git status 2> /dev/null | grep -iw 'modified') ]]; then
echo "[x]"
fi
}
git_st="$yellow`_git_st`$reset"
PS1="$rvm $folder_name $git_branch $git_st \$ "
X 没有回显....我有点迷茫,不知道我做错了什么。
这是我得到的输出:
(ruby-1.9.2-p290) folder-git (master) $ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .rvmrc
#
no changes added to commit (use "git add" and/or "git commit -a")
(ruby-1.9.2-p290) folder-git (master) $