Can I change the input color of my bash prompt to something different than the terminal default

后端 未结 4 463
醉话见心
醉话见心 2020-12-03 15:38

My default terminal color is gray, that\'s fine.

My bash prompt displays a bunch of colors, this works fine:

PS1=\"${COLOR_RED}\\u${COLOR_WHITE}@${CO         


        
4条回答
  •  时光取名叫无心
    2020-12-03 16:11

    I would suggest changing your terminal emulator's settings. It appears you are using iTerm2 (if you are on iTerm, I suggest looking at iTerm2), so:

    Settings -> Profiles -> Your Profile -> Color. Under 'basic colors' adjust 'foreground'

    For just changing the color of the input text, in zsh you could use a

    preexec () { echo -ne "\e[0m" }
    

    Source 1

    I have found a hack-ish way to try this with bash:

    Not natively, but it can be hacked up using the DEBUG trap. This code sets up preexec and precmd functions similar to zsh. The command line is passed as a single argument to preexec.

    Here is a simplified version of the code to set up a precmd function that is executed before running each command.

    preexec () { :; }
    preexec_invoke_exec () {
        [ -n "$COMP_LINE" ] && return  # do nothing if completing
        local this_command=$(history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g");
        preexec "$this_command"
    }
    

    trap 'preexec_invoke_exec' DEBUG This trick is due to Glyph Lefkowitz; thanks to [bcat] for locating the original author.

    http://www.macosxhints.com/dlfiles/preexec.bash.txt

    Source 2

提交回复
热议问题