我在OsX上自定义我的bash提示符,包括git branch以及分支状态的一些标记.这打破了换行.
我知道我必须添加\ [和\]来防止这个问题,但在函数中这样做会显示\ [和\] litteraly.
我该怎么做才能在这些函数中逃避这些序列?
免责声明:这是我第一次尝试使用bash脚本.
function parse_git_dirty {
# TODO make git status response a variable
# [branch+] : working dir has staged changes
if [[ $(git status 2> /dev/null | grep "to be committed") ]]
then S=$S"$(tput setaf 2)+$(tput sgr0)"
fi
# [branch+] : working dir has unstaged changes
if [[ $(git status 2> /dev/null | grep "not staged for commit") ]]
then S=$S"$(tput setaf 1)+$(tput sgr0)"
fi
# [branch+] : working dir has …Run Code Online (Sandbox Code Playgroud)