I am working on a dynamic bash prompt where I want to tell in PS1 which version of the configuration file is included in the local file system. This is a far-fetched example of what I'm trying to do, simplified. What goes wrong: bad wraps and / or brackets appear. Can anyone determine what I am doing wrong?
If the far-fetched configuration matches "v2", I want to see this version in PS1 as YELLOW. If it is "v1", GREEN will appear in the line. Setup:
$ grep FOOVER foo-*.conf foo-v1.conf:
I would then symlink foo.conf foo-v1.conf. My bashrc:
0 GREEN=$(tput setaf 034) 1 YELLOW=$(tput setaf 3) 2 BLUE=$(tput setaf 4) 3 CYAN=$(tput setaf 6) 4 BOLD=$(tput bold) 5 RESET=$(tput sgr0) 6 CONF=$HOME/foo.conf 7 8 function __get_foo_version () { 9 FOOVER=$(grep FOOVER $CONF | awk '{print $3}') 10 if [[ "$FOOVER" =~ v2$ ]]; then 11 style_foover="${BOLD}${YELLOW}$FOOVER" 12
When I run the above, I get this behavior that looks good at first: http://imgur.com/HIR3SoA
But when I arrow up to a long team, bad packaging happens: http://imgur.com/qLfdUor
When I turn off lines 11, 14 and turn on lines 12, 15, I get brackets designed to handle non-printable characters displayed on PS1:
(not enough reputation points to place more than two links :( imgur.com slash nkXFDyJ)
user@host \[\]xyz-v1 ~ $
..and I still get poor packaging in this case.
source share