0
我一直在收拾我的BASH提示符。BASH:用戶輸入的文本顏色不同
目前,它看起來像這樣:
下面是代碼:
# NOTE: OSX uses .bashprofile http://superuser.com/questions/244964/mac-os-x-bashrc-not-working
# http://mywiki.wooledge.org/BashFAQ/037
bold=$(tput bold || tput md)
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 4)
white=$(tput setaf 7 || tput AF 7)
RESET=$(tput sgr0)
# https://github.com/sickill/stderred
export DYLD_INSERT_LIBRARIES="/usr/lib/libstderred.dylib${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"
export STDERRED_ESC_CODE="$bold$red"
pre_prompt()
{
if [ $? = 0 ]; then
echo "$green ✔";
else
echo "$red ✘";
fi
printf "$RESET\n"
printf "$bold"
printf "%[email protected]%s ~ %s:\n" "$USER" "$HOSTNAME" "$PWD"
printf "$RESET"
}
# execs before prompt
export PROMPT_COMMAND=pre_prompt
# \[ ... \] --> http://mywiki.wooledge.org/BashFAQ/053
export PS1="\[$bold$blue\] ⤐ \[$RESET$bold\]"
export PS2="-2-> "
export PS3="-3-> "
export PS4="-4-> "
注意我使用的是超級一小段代碼由sickill有STDERR得到印刷紅。
我還想改善的唯一事情就是用戶輸入的高亮文本。
有沒有辦法做到這一點?
不是那麼簡單,輸出也會使用相同的格式 –