reset the color of the output after my command in bash shell
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I want to distinguish my command from the rest of the output of the shell easily through different colors. But I don't have much experience with customizing my bash shell, so I don't know how to reset the color (after) my input.
my current PS1 variable looks like this:
export PS1="$redu$green$(__git_ps1) $turkw
$white$ "
# '$(__git_ps1)' git status prompt (generates a space before it even if empty)
So my input is white. But even the output of the commands is white because it is not reset. Furthermore, if the command itself color codes its output, then it itself resets the colors which result in some ugly mixing of white and gray.
So how do I reset the color after my input command?
bash
add a comment |Â
up vote
1
down vote
favorite
I want to distinguish my command from the rest of the output of the shell easily through different colors. But I don't have much experience with customizing my bash shell, so I don't know how to reset the color (after) my input.
my current PS1 variable looks like this:
export PS1="$redu$green$(__git_ps1) $turkw
$white$ "
# '$(__git_ps1)' git status prompt (generates a space before it even if empty)
So my input is white. But even the output of the commands is white because it is not reset. Furthermore, if the command itself color codes its output, then it itself resets the colors which result in some ugly mixing of white and gray.
So how do I reset the color after my input command?
bash
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to distinguish my command from the rest of the output of the shell easily through different colors. But I don't have much experience with customizing my bash shell, so I don't know how to reset the color (after) my input.
my current PS1 variable looks like this:
export PS1="$redu$green$(__git_ps1) $turkw
$white$ "
# '$(__git_ps1)' git status prompt (generates a space before it even if empty)
So my input is white. But even the output of the commands is white because it is not reset. Furthermore, if the command itself color codes its output, then it itself resets the colors which result in some ugly mixing of white and gray.
So how do I reset the color after my input command?
bash
I want to distinguish my command from the rest of the output of the shell easily through different colors. But I don't have much experience with customizing my bash shell, so I don't know how to reset the color (after) my input.
my current PS1 variable looks like this:
export PS1="$redu$green$(__git_ps1) $turkw
$white$ "
# '$(__git_ps1)' git status prompt (generates a space before it even if empty)
So my input is white. But even the output of the commands is white because it is not reset. Furthermore, if the command itself color codes its output, then it itself resets the colors which result in some ugly mixing of white and gray.
So how do I reset the color after my input command?
bash
asked Dec 25 '17 at 7:08
Lockon2000
82
82
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
The DEBUG
trap runs before each command, so you can abuse it to reset the colors, if you have colored the command line input. ("abuse" since this isn't debugging.)
With this:
$ promptcol="$(tput sgr0)$(tput setaf 3)"
$ cmdcol="$(tput sgr0)$(tput bold)"
$ normalcol="$(tput sgr0)"
$ trap 'echo -n "$normalcol"' DEBUG
$ PS1="[$promptcol]w$ [$cmdcol]"
I get this:
Note that you need the [...]
surrounding the color codes, so that the shell knows how to calculate the width of the prompt properly. Also, note that you can't put the [...]
within the variables, the shell handles the prompt escapes first, and variable expansions only after that.
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
add a comment |Â
up vote
1
down vote
On the ~/.bash_logout
Insert the following:
echo -e "33[0m"
/usr/bin/clear
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The DEBUG
trap runs before each command, so you can abuse it to reset the colors, if you have colored the command line input. ("abuse" since this isn't debugging.)
With this:
$ promptcol="$(tput sgr0)$(tput setaf 3)"
$ cmdcol="$(tput sgr0)$(tput bold)"
$ normalcol="$(tput sgr0)"
$ trap 'echo -n "$normalcol"' DEBUG
$ PS1="[$promptcol]w$ [$cmdcol]"
I get this:
Note that you need the [...]
surrounding the color codes, so that the shell knows how to calculate the width of the prompt properly. Also, note that you can't put the [...]
within the variables, the shell handles the prompt escapes first, and variable expansions only after that.
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
add a comment |Â
up vote
2
down vote
accepted
The DEBUG
trap runs before each command, so you can abuse it to reset the colors, if you have colored the command line input. ("abuse" since this isn't debugging.)
With this:
$ promptcol="$(tput sgr0)$(tput setaf 3)"
$ cmdcol="$(tput sgr0)$(tput bold)"
$ normalcol="$(tput sgr0)"
$ trap 'echo -n "$normalcol"' DEBUG
$ PS1="[$promptcol]w$ [$cmdcol]"
I get this:
Note that you need the [...]
surrounding the color codes, so that the shell knows how to calculate the width of the prompt properly. Also, note that you can't put the [...]
within the variables, the shell handles the prompt escapes first, and variable expansions only after that.
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The DEBUG
trap runs before each command, so you can abuse it to reset the colors, if you have colored the command line input. ("abuse" since this isn't debugging.)
With this:
$ promptcol="$(tput sgr0)$(tput setaf 3)"
$ cmdcol="$(tput sgr0)$(tput bold)"
$ normalcol="$(tput sgr0)"
$ trap 'echo -n "$normalcol"' DEBUG
$ PS1="[$promptcol]w$ [$cmdcol]"
I get this:
Note that you need the [...]
surrounding the color codes, so that the shell knows how to calculate the width of the prompt properly. Also, note that you can't put the [...]
within the variables, the shell handles the prompt escapes first, and variable expansions only after that.
The DEBUG
trap runs before each command, so you can abuse it to reset the colors, if you have colored the command line input. ("abuse" since this isn't debugging.)
With this:
$ promptcol="$(tput sgr0)$(tput setaf 3)"
$ cmdcol="$(tput sgr0)$(tput bold)"
$ normalcol="$(tput sgr0)"
$ trap 'echo -n "$normalcol"' DEBUG
$ PS1="[$promptcol]w$ [$cmdcol]"
I get this:
Note that you need the [...]
surrounding the color codes, so that the shell knows how to calculate the width of the prompt properly. Also, note that you can't put the [...]
within the variables, the shell handles the prompt escapes first, and variable expansions only after that.
answered Dec 25 '17 at 10:32
ilkkachu
49.9k674137
49.9k674137
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
add a comment |Â
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Okay, if I understand your answer correctly, you say that with (trap '.....' DEBUG) I can add personalized commands to be executed whenever the DEBUG trap runs (without changing its former code, I am just adding to it). So by adding something like this (trap 'echo -n -e "e[0m"' DEBUG) in my .bash_profile (before the PS1 variable) I should get the desired behavior. Okay, I tried it out and it worked. But did I really understand everything correctly?? And thanks for your help :)
â Lockon2000
Dec 26 '17 at 17:13
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
Ah, also I amended my PS1 variable as you suggested. Now it looks like this PS1="[$red]u[$green]$(__git_ps1) [$turk]w [$white]$ "
â Lockon2000
Dec 26 '17 at 17:16
add a comment |Â
up vote
1
down vote
On the ~/.bash_logout
Insert the following:
echo -e "33[0m"
/usr/bin/clear
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
add a comment |Â
up vote
1
down vote
On the ~/.bash_logout
Insert the following:
echo -e "33[0m"
/usr/bin/clear
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
add a comment |Â
up vote
1
down vote
up vote
1
down vote
On the ~/.bash_logout
Insert the following:
echo -e "33[0m"
/usr/bin/clear
On the ~/.bash_logout
Insert the following:
echo -e "33[0m"
/usr/bin/clear
answered Dec 25 '17 at 7:24
ñÃÂñýàñüÃÂÃÂùcñ÷
407418
407418
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
add a comment |Â
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
maybe you didn't get what I want correctly. What I want is somthing to change back the colors (reset all attributes) after (entering) each and every command, not after finishing my entire session.
â Lockon2000
Dec 26 '17 at 17:00
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412900%2freset-the-color-of-the-output-after-my-command-in-bash-shell%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password