How do I stop a bash shell PS1 color to stop at the end of the command?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
10
down vote

favorite
2












I have a custom PS1 colour where I have the actual shell commands in a distinct colour, just so I can quickly see what commands I typed and separate it from the command output itself.



Suppose the colour in PS1 is set to 'blue' for command prompt and the default colour in my shell is white.



  • I type a command e.g. ls, (ls -l is coloured blue)

  • The output it generates, first line is still blue

  • All remaining line comes as white

What I want is all the output after the command to be 'white'.



Another example:



  • I type a command 'cat ', colour is blue

  • The output comes, the whole output is blue

I would like the output to be 'white' while keeping the command prompt I typed 'blue'



On some commands, it is fine, other commands, the same colour overflows into the first line of the output and then the default colour kicks in and some other commands, the whole output (e.g. cat) has the same colour.



Is there a way to keep just the commands I typed in one colour and the rest to the default?



I'm on OSX.



EDIT #1



Here's a screenshot that @derobert's linked to in the comments that shows what I'm looking for.



                 ss#1










share|improve this question



















  • 2




    You need to show us your prompt so we can pinpoint the errors.
    – glenn jackman
    Jul 23 '14 at 15:51














up vote
10
down vote

favorite
2












I have a custom PS1 colour where I have the actual shell commands in a distinct colour, just so I can quickly see what commands I typed and separate it from the command output itself.



Suppose the colour in PS1 is set to 'blue' for command prompt and the default colour in my shell is white.



  • I type a command e.g. ls, (ls -l is coloured blue)

  • The output it generates, first line is still blue

  • All remaining line comes as white

What I want is all the output after the command to be 'white'.



Another example:



  • I type a command 'cat ', colour is blue

  • The output comes, the whole output is blue

I would like the output to be 'white' while keeping the command prompt I typed 'blue'



On some commands, it is fine, other commands, the same colour overflows into the first line of the output and then the default colour kicks in and some other commands, the whole output (e.g. cat) has the same colour.



Is there a way to keep just the commands I typed in one colour and the rest to the default?



I'm on OSX.



EDIT #1



Here's a screenshot that @derobert's linked to in the comments that shows what I'm looking for.



                 ss#1










share|improve this question



















  • 2




    You need to show us your prompt so we can pinpoint the errors.
    – glenn jackman
    Jul 23 '14 at 15:51












up vote
10
down vote

favorite
2









up vote
10
down vote

favorite
2






2





I have a custom PS1 colour where I have the actual shell commands in a distinct colour, just so I can quickly see what commands I typed and separate it from the command output itself.



Suppose the colour in PS1 is set to 'blue' for command prompt and the default colour in my shell is white.



  • I type a command e.g. ls, (ls -l is coloured blue)

  • The output it generates, first line is still blue

  • All remaining line comes as white

What I want is all the output after the command to be 'white'.



Another example:



  • I type a command 'cat ', colour is blue

  • The output comes, the whole output is blue

I would like the output to be 'white' while keeping the command prompt I typed 'blue'



On some commands, it is fine, other commands, the same colour overflows into the first line of the output and then the default colour kicks in and some other commands, the whole output (e.g. cat) has the same colour.



Is there a way to keep just the commands I typed in one colour and the rest to the default?



I'm on OSX.



EDIT #1



Here's a screenshot that @derobert's linked to in the comments that shows what I'm looking for.



                 ss#1










share|improve this question















I have a custom PS1 colour where I have the actual shell commands in a distinct colour, just so I can quickly see what commands I typed and separate it from the command output itself.



Suppose the colour in PS1 is set to 'blue' for command prompt and the default colour in my shell is white.



  • I type a command e.g. ls, (ls -l is coloured blue)

  • The output it generates, first line is still blue

  • All remaining line comes as white

What I want is all the output after the command to be 'white'.



Another example:



  • I type a command 'cat ', colour is blue

  • The output comes, the whole output is blue

I would like the output to be 'white' while keeping the command prompt I typed 'blue'



On some commands, it is fine, other commands, the same colour overflows into the first line of the output and then the default colour kicks in and some other commands, the whole output (e.g. cat) has the same colour.



Is there a way to keep just the commands I typed in one colour and the rest to the default?



I'm on OSX.



EDIT #1



Here's a screenshot that @derobert's linked to in the comments that shows what I'm looking for.



                 ss#1







bash prompt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 at 0:49









Rui F Ribeiro

38.3k1477127




38.3k1477127










asked Jul 23 '14 at 15:36









iQ.

1535




1535







  • 2




    You need to show us your prompt so we can pinpoint the errors.
    – glenn jackman
    Jul 23 '14 at 15:51












  • 2




    You need to show us your prompt so we can pinpoint the errors.
    – glenn jackman
    Jul 23 '14 at 15:51







2




2




You need to show us your prompt so we can pinpoint the errors.
– glenn jackman
Jul 23 '14 at 15:51




You need to show us your prompt so we can pinpoint the errors.
– glenn jackman
Jul 23 '14 at 15:51










1 Answer
1






active

oldest

votes

















up vote
11
down vote



accepted










You're basically wanting to reset the terminal color right before bash executes the command. This can be done with a trap.



For example:



trap '[[ -t 1 ]] && tput sgr0' DEBUG


Bash executes the DEBUG trap immediately before the command, so this will result in tput sgr0 (which resets formatting attributes) being run before each command.



The [[ -t 1 ]] is a safety check to make sure that STDOUT is actually a terminal. There might be some cases where bash's STDOUT isn't connected to a terminal (piping, remote ssh, etc), and so you don't want tput to send terminal escape codes.






share|improve this answer






















  • Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
    – polym
    Jul 23 '14 at 15:55







  • 1




    @polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
    – Patrick
    Jul 23 '14 at 15:55











  • ok wow that works. Any possibility that this can go wrong?
    – polym
    Jul 23 '14 at 15:57










  • @polym not any more
    – Patrick
    Jul 23 '14 at 16:05










  • brilliant, that's exactly what i needed to reset the terminal colour.
    – iQ.
    Jul 23 '14 at 16:29










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f146145%2fhow-do-i-stop-a-bash-shell-ps1-color-to-stop-at-the-end-of-the-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
11
down vote



accepted










You're basically wanting to reset the terminal color right before bash executes the command. This can be done with a trap.



For example:



trap '[[ -t 1 ]] && tput sgr0' DEBUG


Bash executes the DEBUG trap immediately before the command, so this will result in tput sgr0 (which resets formatting attributes) being run before each command.



The [[ -t 1 ]] is a safety check to make sure that STDOUT is actually a terminal. There might be some cases where bash's STDOUT isn't connected to a terminal (piping, remote ssh, etc), and so you don't want tput to send terminal escape codes.






share|improve this answer






















  • Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
    – polym
    Jul 23 '14 at 15:55







  • 1




    @polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
    – Patrick
    Jul 23 '14 at 15:55











  • ok wow that works. Any possibility that this can go wrong?
    – polym
    Jul 23 '14 at 15:57










  • @polym not any more
    – Patrick
    Jul 23 '14 at 16:05










  • brilliant, that's exactly what i needed to reset the terminal colour.
    – iQ.
    Jul 23 '14 at 16:29














up vote
11
down vote



accepted










You're basically wanting to reset the terminal color right before bash executes the command. This can be done with a trap.



For example:



trap '[[ -t 1 ]] && tput sgr0' DEBUG


Bash executes the DEBUG trap immediately before the command, so this will result in tput sgr0 (which resets formatting attributes) being run before each command.



The [[ -t 1 ]] is a safety check to make sure that STDOUT is actually a terminal. There might be some cases where bash's STDOUT isn't connected to a terminal (piping, remote ssh, etc), and so you don't want tput to send terminal escape codes.






share|improve this answer






















  • Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
    – polym
    Jul 23 '14 at 15:55







  • 1




    @polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
    – Patrick
    Jul 23 '14 at 15:55











  • ok wow that works. Any possibility that this can go wrong?
    – polym
    Jul 23 '14 at 15:57










  • @polym not any more
    – Patrick
    Jul 23 '14 at 16:05










  • brilliant, that's exactly what i needed to reset the terminal colour.
    – iQ.
    Jul 23 '14 at 16:29












up vote
11
down vote



accepted







up vote
11
down vote



accepted






You're basically wanting to reset the terminal color right before bash executes the command. This can be done with a trap.



For example:



trap '[[ -t 1 ]] && tput sgr0' DEBUG


Bash executes the DEBUG trap immediately before the command, so this will result in tput sgr0 (which resets formatting attributes) being run before each command.



The [[ -t 1 ]] is a safety check to make sure that STDOUT is actually a terminal. There might be some cases where bash's STDOUT isn't connected to a terminal (piping, remote ssh, etc), and so you don't want tput to send terminal escape codes.






share|improve this answer














You're basically wanting to reset the terminal color right before bash executes the command. This can be done with a trap.



For example:



trap '[[ -t 1 ]] && tput sgr0' DEBUG


Bash executes the DEBUG trap immediately before the command, so this will result in tput sgr0 (which resets formatting attributes) being run before each command.



The [[ -t 1 ]] is a safety check to make sure that STDOUT is actually a terminal. There might be some cases where bash's STDOUT isn't connected to a terminal (piping, remote ssh, etc), and so you don't want tput to send terminal escape codes.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 23 '14 at 16:05

























answered Jul 23 '14 at 15:53









Patrick

49.4k11126178




49.4k11126178











  • Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
    – polym
    Jul 23 '14 at 15:55







  • 1




    @polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
    – Patrick
    Jul 23 '14 at 15:55











  • ok wow that works. Any possibility that this can go wrong?
    – polym
    Jul 23 '14 at 15:57










  • @polym not any more
    – Patrick
    Jul 23 '14 at 16:05










  • brilliant, that's exactly what i needed to reset the terminal colour.
    – iQ.
    Jul 23 '14 at 16:29
















  • Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
    – polym
    Jul 23 '14 at 15:55







  • 1




    @polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
    – Patrick
    Jul 23 '14 at 15:55











  • ok wow that works. Any possibility that this can go wrong?
    – polym
    Jul 23 '14 at 15:57










  • @polym not any more
    – Patrick
    Jul 23 '14 at 16:05










  • brilliant, that's exactly what i needed to reset the terminal colour.
    – iQ.
    Jul 23 '14 at 16:29















Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
– polym
Jul 23 '14 at 15:55





Where do you put this? Let's say PS1 doesn't set back the color. Now how do you add this line to execute this command right after the user put in his command and pressed enter?
– polym
Jul 23 '14 at 15:55





1




1




@polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
– Patrick
Jul 23 '14 at 15:55





@polym in your .bashrc (or wherever $PS1 is set). I'd put it right next to the $PS1 definition so you know they're related.
– Patrick
Jul 23 '14 at 15:55













ok wow that works. Any possibility that this can go wrong?
– polym
Jul 23 '14 at 15:57




ok wow that works. Any possibility that this can go wrong?
– polym
Jul 23 '14 at 15:57












@polym not any more
– Patrick
Jul 23 '14 at 16:05




@polym not any more
– Patrick
Jul 23 '14 at 16:05












brilliant, that's exactly what i needed to reset the terminal colour.
– iQ.
Jul 23 '14 at 16:29




brilliant, that's exactly what i needed to reset the terminal colour.
– iQ.
Jul 23 '14 at 16:29

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f146145%2fhow-do-i-stop-a-bash-shell-ps1-color-to-stop-at-the-end-of-the-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)