Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There are a number of tutorials/posts online (e.g. http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/) about how to customize your prompt in bash by setting PS1. Is there a way to customize the color/bolding of the command I type?

In other words, as an example lets say that I wanted a green prompt, a bold blue command, and then output in whatever colors would be default. In the example below, I already know how to make "joe>" show as green, blue, bold, whatever by setting PS1. But is there a way I can I make "git status' show as bold for example?

joe> git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
...
share|improve this question
    
If you want a really good shell you should use zsh,what you want to achieve there would be very simple with preexec() { printf '\e[0m' } –  bollovan Sep 18 '11 at 9:32
2  
@bollovan - 'Really good' is a bit subjective, I find it really detestable because of its bloat and POSIX noncompliance. But, whatever floats your boat. –  Chris Down Sep 18 '11 at 12:38
    
@ChrisDown bloat floats your boat - never heard it, quite amusing. –  naxa Mar 14 '13 at 13:14

1 Answer 1

You'd have to leave a colour trailing after the PS1 (start it after > in your example), and then use the bash DEBUG trap to clear the colour before your command was run (but after you press enter in your shell. Try something like this:

shopt -s extdebug
trap "tput sgr0" DEBUG
share|improve this answer
    
for someone stranger to escape codes: would this preserve the original coloring of the command (eg. would ls --color=always be colored)? –  naxa Mar 14 '13 at 13:16
    
@naxa - Yes, as this explicitly sets colour codes (except for colours that are colored in the default terminal colour, which will only take effect after the first colour). –  Chris Down Mar 15 '13 at 1:13
    
This trick seems to interfere with tab completion (prints weird things like ^[(B^[[m). It happens only on some systems, though: I tested this on two systems, both running Ubuntu 12.04 LTS, and only one of them had the interference. –  musiphil Jul 15 '13 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.