How do I change bash prompt in gnome terminal without messing up terminal title in Ubuntu 16?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I don't like all long directory paths to feel up my terminal's space so, I truncate them through a python script. I have edited the .bashrc file and replaced PS1 to
export PROMPT_COMMAND='PS1="$(python /home/vinay/bash_promt.py)"'.
And when I do that terminal's title doesn't work anymore. It simply displays Terminal
Which is irritating. I can change the title manually by running following command in bash:
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
Is there a way to set terminal's title to the custom prompt which is being set in my bash.
16.04 gnome-terminal ubuntu-gnome
bumped to the homepage by Community♦ 15 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I don't like all long directory paths to feel up my terminal's space so, I truncate them through a python script. I have edited the .bashrc file and replaced PS1 to
export PROMPT_COMMAND='PS1="$(python /home/vinay/bash_promt.py)"'.
And when I do that terminal's title doesn't work anymore. It simply displays Terminal
Which is irritating. I can change the title manually by running following command in bash:
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
Is there a way to set terminal's title to the custom prompt which is being set in my bash.
16.04 gnome-terminal ubuntu-gnome
bumped to the homepage by Community♦ 15 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
3
You know there's aPROMPT_DIRTRIM
variable that controls the number of directory components, right?
– steeldriver
May 15 '16 at 10:57
Also, thefish
shell does this by default (and it has many other cool features too).
– Andrea Lazzarotto
May 15 '16 at 11:21
add a comment |
I don't like all long directory paths to feel up my terminal's space so, I truncate them through a python script. I have edited the .bashrc file and replaced PS1 to
export PROMPT_COMMAND='PS1="$(python /home/vinay/bash_promt.py)"'.
And when I do that terminal's title doesn't work anymore. It simply displays Terminal
Which is irritating. I can change the title manually by running following command in bash:
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
Is there a way to set terminal's title to the custom prompt which is being set in my bash.
16.04 gnome-terminal ubuntu-gnome
I don't like all long directory paths to feel up my terminal's space so, I truncate them through a python script. I have edited the .bashrc file and replaced PS1 to
export PROMPT_COMMAND='PS1="$(python /home/vinay/bash_promt.py)"'.
And when I do that terminal's title doesn't work anymore. It simply displays Terminal
Which is irritating. I can change the title manually by running following command in bash:
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
Is there a way to set terminal's title to the custom prompt which is being set in my bash.
16.04 gnome-terminal ubuntu-gnome
16.04 gnome-terminal ubuntu-gnome
edited May 15 '16 at 13:09
Sinscary
875622
875622
asked May 15 '16 at 9:17
Vinay TiwaryVinay Tiwary
1112
1112
bumped to the homepage by Community♦ 15 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 15 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
3
You know there's aPROMPT_DIRTRIM
variable that controls the number of directory components, right?
– steeldriver
May 15 '16 at 10:57
Also, thefish
shell does this by default (and it has many other cool features too).
– Andrea Lazzarotto
May 15 '16 at 11:21
add a comment |
3
You know there's aPROMPT_DIRTRIM
variable that controls the number of directory components, right?
– steeldriver
May 15 '16 at 10:57
Also, thefish
shell does this by default (and it has many other cool features too).
– Andrea Lazzarotto
May 15 '16 at 11:21
3
3
You know there's a
PROMPT_DIRTRIM
variable that controls the number of directory components, right?– steeldriver
May 15 '16 at 10:57
You know there's a
PROMPT_DIRTRIM
variable that controls the number of directory components, right?– steeldriver
May 15 '16 at 10:57
Also, the
fish
shell does this by default (and it has many other cool features too).– Andrea Lazzarotto
May 15 '16 at 11:21
Also, the
fish
shell does this by default (and it has many other cool features too).– Andrea Lazzarotto
May 15 '16 at 11:21
add a comment |
3 Answers
3
active
oldest
votes
For gnome-terminal, the terminal title is set via PROMPT_COMMAND
which is defined in /etc/profile.d/vte-2.91.sh
.
PROMPT_COMMAND
, as defined in this script, does two things:
changes the terminal title using the OSC 0 escape sequence (
33]0;NEW_TITLE07
),changes the terminal's notion of the current directory using the OSC 7 escape sequence (
33]7;NEW_CURRENT_DIRECTORY07
, this is factored out to the__vte_osc7
function).
Should you remove the second one from your PROMPT_COMMAND
, your newly opened terminal windows or tabs wouldn't open in the directory where you were standing in the previous terminal. Most likely you don't want this.
So, in your shell startup scripts, after sourcing vte-2.91.sh
you have to construct your preferred PROMPT_COMMAND
that sets the title in a similar manner to vte-2.91.sh
, and sets the current working directory exactly as it's done by default.
I'm not aware of any way to refer to PS1
's resolved value (that is, after substituting the username and such) inside PROMPT_COMMAND
or anywhere else (let alone filter out the escape sequences such as color changes). If you wish to see the same string in your prompt and in the window title, I believe you need to duplicate the construction of that string for PS1
and PROMPT_COMMAND
.
add a comment |
This will work for you
open ~/.bashrc
. Find the line that says:
PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Comment out this line, by putting a #
character in front of it:
# PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Now add this line (you may want to put it just after the commented-out line):
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
Replace Custom Name
with whatever you want to change the Terminal title to be.
Hope this helps.
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by runningPROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your~/.bashrc
file. hope you won't mind giving it a shot.
– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you runPROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.
– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
|
show 1 more comment
The escape sequence to use is ESC]2;new titleBEL where ESC and BEL are the escape and bell characters. Like [e]2;NEWTITLEa]
. Using #Bash escape sequences, changing the title in your prompt looks like:
export PS1='[e]2;new titlea]prompt > '
doc ref
So an example of a multi-color truncated bash prompt that also has a custom terminal title is:
export PS1='[e]2;$PWDa]e[93m$USERe[97m@e[90m$HOSTNAME e[93m$ e[0m'
In that example the terminal title will always reflect the present working directory ($PWD
) and the terminal prompt will always look like the following regardless of what directory you are in: user@hostname $
.
You can replace $PWD
with CUSTOM TITLE
to make the terminal title always reflect CUSTOM TITLE
.
Update
Be careful when not wrapping non-printed characters in [
and ]
. It works without it and I've been doing it without them for years. However, as I found out today with some setups, it can cause some issues in terminal. Below is a cleaner version using variables and wrapping the color codes:
T_YELLOW='[e[93m]'
T_WHITE='[e[97m]'
T_GRAY='[e[90m]'
T_DEFAULT='[e[0m]'
T_TITLE='[e]2;$PWDa]'
export PS1="${T_TITLE}${T_YELLOW}$USER${T_WHITE}@${T_GRAY}$HOSTNAME${T_YELLOW} $ ${T_DEFAULT}"
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f772655%2fhow-do-i-change-bash-prompt-in-gnome-terminal-without-messing-up-terminal-title%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
For gnome-terminal, the terminal title is set via PROMPT_COMMAND
which is defined in /etc/profile.d/vte-2.91.sh
.
PROMPT_COMMAND
, as defined in this script, does two things:
changes the terminal title using the OSC 0 escape sequence (
33]0;NEW_TITLE07
),changes the terminal's notion of the current directory using the OSC 7 escape sequence (
33]7;NEW_CURRENT_DIRECTORY07
, this is factored out to the__vte_osc7
function).
Should you remove the second one from your PROMPT_COMMAND
, your newly opened terminal windows or tabs wouldn't open in the directory where you were standing in the previous terminal. Most likely you don't want this.
So, in your shell startup scripts, after sourcing vte-2.91.sh
you have to construct your preferred PROMPT_COMMAND
that sets the title in a similar manner to vte-2.91.sh
, and sets the current working directory exactly as it's done by default.
I'm not aware of any way to refer to PS1
's resolved value (that is, after substituting the username and such) inside PROMPT_COMMAND
or anywhere else (let alone filter out the escape sequences such as color changes). If you wish to see the same string in your prompt and in the window title, I believe you need to duplicate the construction of that string for PS1
and PROMPT_COMMAND
.
add a comment |
For gnome-terminal, the terminal title is set via PROMPT_COMMAND
which is defined in /etc/profile.d/vte-2.91.sh
.
PROMPT_COMMAND
, as defined in this script, does two things:
changes the terminal title using the OSC 0 escape sequence (
33]0;NEW_TITLE07
),changes the terminal's notion of the current directory using the OSC 7 escape sequence (
33]7;NEW_CURRENT_DIRECTORY07
, this is factored out to the__vte_osc7
function).
Should you remove the second one from your PROMPT_COMMAND
, your newly opened terminal windows or tabs wouldn't open in the directory where you were standing in the previous terminal. Most likely you don't want this.
So, in your shell startup scripts, after sourcing vte-2.91.sh
you have to construct your preferred PROMPT_COMMAND
that sets the title in a similar manner to vte-2.91.sh
, and sets the current working directory exactly as it's done by default.
I'm not aware of any way to refer to PS1
's resolved value (that is, after substituting the username and such) inside PROMPT_COMMAND
or anywhere else (let alone filter out the escape sequences such as color changes). If you wish to see the same string in your prompt and in the window title, I believe you need to duplicate the construction of that string for PS1
and PROMPT_COMMAND
.
add a comment |
For gnome-terminal, the terminal title is set via PROMPT_COMMAND
which is defined in /etc/profile.d/vte-2.91.sh
.
PROMPT_COMMAND
, as defined in this script, does two things:
changes the terminal title using the OSC 0 escape sequence (
33]0;NEW_TITLE07
),changes the terminal's notion of the current directory using the OSC 7 escape sequence (
33]7;NEW_CURRENT_DIRECTORY07
, this is factored out to the__vte_osc7
function).
Should you remove the second one from your PROMPT_COMMAND
, your newly opened terminal windows or tabs wouldn't open in the directory where you were standing in the previous terminal. Most likely you don't want this.
So, in your shell startup scripts, after sourcing vte-2.91.sh
you have to construct your preferred PROMPT_COMMAND
that sets the title in a similar manner to vte-2.91.sh
, and sets the current working directory exactly as it's done by default.
I'm not aware of any way to refer to PS1
's resolved value (that is, after substituting the username and such) inside PROMPT_COMMAND
or anywhere else (let alone filter out the escape sequences such as color changes). If you wish to see the same string in your prompt and in the window title, I believe you need to duplicate the construction of that string for PS1
and PROMPT_COMMAND
.
For gnome-terminal, the terminal title is set via PROMPT_COMMAND
which is defined in /etc/profile.d/vte-2.91.sh
.
PROMPT_COMMAND
, as defined in this script, does two things:
changes the terminal title using the OSC 0 escape sequence (
33]0;NEW_TITLE07
),changes the terminal's notion of the current directory using the OSC 7 escape sequence (
33]7;NEW_CURRENT_DIRECTORY07
, this is factored out to the__vte_osc7
function).
Should you remove the second one from your PROMPT_COMMAND
, your newly opened terminal windows or tabs wouldn't open in the directory where you were standing in the previous terminal. Most likely you don't want this.
So, in your shell startup scripts, after sourcing vte-2.91.sh
you have to construct your preferred PROMPT_COMMAND
that sets the title in a similar manner to vte-2.91.sh
, and sets the current working directory exactly as it's done by default.
I'm not aware of any way to refer to PS1
's resolved value (that is, after substituting the username and such) inside PROMPT_COMMAND
or anywhere else (let alone filter out the escape sequences such as color changes). If you wish to see the same string in your prompt and in the window title, I believe you need to duplicate the construction of that string for PS1
and PROMPT_COMMAND
.
answered May 15 '16 at 11:54
egmontegmont
4,44611126
4,44611126
add a comment |
add a comment |
This will work for you
open ~/.bashrc
. Find the line that says:
PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Comment out this line, by putting a #
character in front of it:
# PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Now add this line (you may want to put it just after the commented-out line):
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
Replace Custom Name
with whatever you want to change the Terminal title to be.
Hope this helps.
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by runningPROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your~/.bashrc
file. hope you won't mind giving it a shot.
– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you runPROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.
– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
|
show 1 more comment
This will work for you
open ~/.bashrc
. Find the line that says:
PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Comment out this line, by putting a #
character in front of it:
# PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Now add this line (you may want to put it just after the commented-out line):
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
Replace Custom Name
with whatever you want to change the Terminal title to be.
Hope this helps.
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by runningPROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your~/.bashrc
file. hope you won't mind giving it a shot.
– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you runPROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.
– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
|
show 1 more comment
This will work for you
open ~/.bashrc
. Find the line that says:
PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Comment out this line, by putting a #
character in front of it:
# PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Now add this line (you may want to put it just after the commented-out line):
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
Replace Custom Name
with whatever you want to change the Terminal title to be.
Hope this helps.
This will work for you
open ~/.bashrc
. Find the line that says:
PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Comment out this line, by putting a #
character in front of it:
# PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
Now add this line (you may want to put it just after the commented-out line):
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
Replace Custom Name
with whatever you want to change the Terminal title to be.
Hope this helps.
answered May 15 '16 at 9:31
SinscarySinscary
875622
875622
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by runningPROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your~/.bashrc
file. hope you won't mind giving it a shot.
– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you runPROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.
– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
|
show 1 more comment
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by runningPROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your~/.bashrc
file. hope you won't mind giving it a shot.
– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you runPROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.
– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
Nope! This doesn't work at all. Same command I've mention in my question only. I believe you didn't get my question correctly. Firing up this command resets my bash promp, which I don't want.
– Vinay Tiwary
May 17 '16 at 5:12
if i am not wrong you said that you can change title by running
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your ~/.bashrc
file. hope you won't mind giving it a shot.– Sinscary
May 17 '16 at 13:55
if i am not wrong you said that you can change title by running
PROMPT_COMMAND='echo -ne "33]0;Custom Name07"'
. If that's the case than if you take a moment to read my answer carefully you will see that i asked you to add that line to your ~/.bashrc
file. hope you won't mind giving it a shot.– Sinscary
May 17 '16 at 13:55
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
No offence!! But I tried the command before posting the question here.
– Vinay Tiwary
May 19 '16 at 8:00
dude when you run
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.– Sinscary
May 19 '16 at 8:16
dude when you run
PROMPT_COMMAND='echo -ne "33]0;CUSTOM TITLE07"'
does it changed your title.– Sinscary
May 19 '16 at 8:16
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
Yes bro it changes title as I said in question but then it restores original bash prompt.
– Vinay Tiwary
May 24 '16 at 6:12
|
show 1 more comment
The escape sequence to use is ESC]2;new titleBEL where ESC and BEL are the escape and bell characters. Like [e]2;NEWTITLEa]
. Using #Bash escape sequences, changing the title in your prompt looks like:
export PS1='[e]2;new titlea]prompt > '
doc ref
So an example of a multi-color truncated bash prompt that also has a custom terminal title is:
export PS1='[e]2;$PWDa]e[93m$USERe[97m@e[90m$HOSTNAME e[93m$ e[0m'
In that example the terminal title will always reflect the present working directory ($PWD
) and the terminal prompt will always look like the following regardless of what directory you are in: user@hostname $
.
You can replace $PWD
with CUSTOM TITLE
to make the terminal title always reflect CUSTOM TITLE
.
Update
Be careful when not wrapping non-printed characters in [
and ]
. It works without it and I've been doing it without them for years. However, as I found out today with some setups, it can cause some issues in terminal. Below is a cleaner version using variables and wrapping the color codes:
T_YELLOW='[e[93m]'
T_WHITE='[e[97m]'
T_GRAY='[e[90m]'
T_DEFAULT='[e[0m]'
T_TITLE='[e]2;$PWDa]'
export PS1="${T_TITLE}${T_YELLOW}$USER${T_WHITE}@${T_GRAY}$HOSTNAME${T_YELLOW} $ ${T_DEFAULT}"
add a comment |
The escape sequence to use is ESC]2;new titleBEL where ESC and BEL are the escape and bell characters. Like [e]2;NEWTITLEa]
. Using #Bash escape sequences, changing the title in your prompt looks like:
export PS1='[e]2;new titlea]prompt > '
doc ref
So an example of a multi-color truncated bash prompt that also has a custom terminal title is:
export PS1='[e]2;$PWDa]e[93m$USERe[97m@e[90m$HOSTNAME e[93m$ e[0m'
In that example the terminal title will always reflect the present working directory ($PWD
) and the terminal prompt will always look like the following regardless of what directory you are in: user@hostname $
.
You can replace $PWD
with CUSTOM TITLE
to make the terminal title always reflect CUSTOM TITLE
.
Update
Be careful when not wrapping non-printed characters in [
and ]
. It works without it and I've been doing it without them for years. However, as I found out today with some setups, it can cause some issues in terminal. Below is a cleaner version using variables and wrapping the color codes:
T_YELLOW='[e[93m]'
T_WHITE='[e[97m]'
T_GRAY='[e[90m]'
T_DEFAULT='[e[0m]'
T_TITLE='[e]2;$PWDa]'
export PS1="${T_TITLE}${T_YELLOW}$USER${T_WHITE}@${T_GRAY}$HOSTNAME${T_YELLOW} $ ${T_DEFAULT}"
add a comment |
The escape sequence to use is ESC]2;new titleBEL where ESC and BEL are the escape and bell characters. Like [e]2;NEWTITLEa]
. Using #Bash escape sequences, changing the title in your prompt looks like:
export PS1='[e]2;new titlea]prompt > '
doc ref
So an example of a multi-color truncated bash prompt that also has a custom terminal title is:
export PS1='[e]2;$PWDa]e[93m$USERe[97m@e[90m$HOSTNAME e[93m$ e[0m'
In that example the terminal title will always reflect the present working directory ($PWD
) and the terminal prompt will always look like the following regardless of what directory you are in: user@hostname $
.
You can replace $PWD
with CUSTOM TITLE
to make the terminal title always reflect CUSTOM TITLE
.
Update
Be careful when not wrapping non-printed characters in [
and ]
. It works without it and I've been doing it without them for years. However, as I found out today with some setups, it can cause some issues in terminal. Below is a cleaner version using variables and wrapping the color codes:
T_YELLOW='[e[93m]'
T_WHITE='[e[97m]'
T_GRAY='[e[90m]'
T_DEFAULT='[e[0m]'
T_TITLE='[e]2;$PWDa]'
export PS1="${T_TITLE}${T_YELLOW}$USER${T_WHITE}@${T_GRAY}$HOSTNAME${T_YELLOW} $ ${T_DEFAULT}"
The escape sequence to use is ESC]2;new titleBEL where ESC and BEL are the escape and bell characters. Like [e]2;NEWTITLEa]
. Using #Bash escape sequences, changing the title in your prompt looks like:
export PS1='[e]2;new titlea]prompt > '
doc ref
So an example of a multi-color truncated bash prompt that also has a custom terminal title is:
export PS1='[e]2;$PWDa]e[93m$USERe[97m@e[90m$HOSTNAME e[93m$ e[0m'
In that example the terminal title will always reflect the present working directory ($PWD
) and the terminal prompt will always look like the following regardless of what directory you are in: user@hostname $
.
You can replace $PWD
with CUSTOM TITLE
to make the terminal title always reflect CUSTOM TITLE
.
Update
Be careful when not wrapping non-printed characters in [
and ]
. It works without it and I've been doing it without them for years. However, as I found out today with some setups, it can cause some issues in terminal. Below is a cleaner version using variables and wrapping the color codes:
T_YELLOW='[e[93m]'
T_WHITE='[e[97m]'
T_GRAY='[e[90m]'
T_DEFAULT='[e[0m]'
T_TITLE='[e]2;$PWDa]'
export PS1="${T_TITLE}${T_YELLOW}$USER${T_WHITE}@${T_GRAY}$HOSTNAME${T_YELLOW} $ ${T_DEFAULT}"
edited Nov 10 '17 at 20:44
answered Nov 4 '17 at 13:00
jtlindseyjtlindsey
4811616
4811616
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f772655%2fhow-do-i-change-bash-prompt-in-gnome-terminal-without-messing-up-terminal-title%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
3
You know there's a
PROMPT_DIRTRIM
variable that controls the number of directory components, right?– steeldriver
May 15 '16 at 10:57
Also, the
fish
shell does this by default (and it has many other cool features too).– Andrea Lazzarotto
May 15 '16 at 11:21