Getting a dynamic bash prompt PS1 right

本小妞迷上赌 提交于 2019-12-05 10:27:20
Cobi

Use \x01 (or \001) and \x02 (or \002) and then evaluate them with echo -e:

    function __get_foo_version () {
      FOOVER=$(grep FOOVER $CONF | awk '{print $3}')
      if [[ "$FOOVER" =~ v2$ ]]; then
        #style_foover="${BOLD}${YELLOW}$FOOVER"
>>>     style_foover="\x01${BOLD}${YELLOW}\x02$FOOVER"
      elif [[ "$FOOVER" =~ v1$ ]]; then
        #style_foover="${BOLD}${GREEN}$FOOVER"
>>>     style_foover="\x01${BOLD}${GREEN}\x02$FOOVER"
      fi
>>>   echo -e "$style_foover"
    }

A more complete answer as to why this fixes it is here: https://superuser.com/questions/301353/escape-non-printing-characters-in-a-function-for-a-bash-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!