Bash prompt configuration

Clash Royale CLAN TAG#URR8PPP
I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
I used zsh before, and for some reasons I want to go back to bash but I'd love
to get the same prompt "theme" that I had with zsh, whish was very sober.

I especially like the way it only display the first character of the directories names in the path except the current one.
I'm searching how I could write this in the .bashrc but I'm not finding anything.
bash prompt bashrc
add a comment |
I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
I used zsh before, and for some reasons I want to go back to bash but I'd love
to get the same prompt "theme" that I had with zsh, whish was very sober.

I especially like the way it only display the first character of the directories names in the path except the current one.
I'm searching how I could write this in the .bashrc but I'm not finding anything.
bash prompt bashrc
add a comment |
I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
I used zsh before, and for some reasons I want to go back to bash but I'd love
to get the same prompt "theme" that I had with zsh, whish was very sober.

I especially like the way it only display the first character of the directories names in the path except the current one.
I'm searching how I could write this in the .bashrc but I'm not finding anything.
bash prompt bashrc
I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
I used zsh before, and for some reasons I want to go back to bash but I'd love
to get the same prompt "theme" that I had with zsh, whish was very sober.

I especially like the way it only display the first character of the directories names in the path except the current one.
I'm searching how I could write this in the .bashrc but I'm not finding anything.
bash prompt bashrc
bash prompt bashrc
edited Dec 21 '18 at 0:00
Rui F Ribeiro
39.1k1479130
39.1k1479130
asked Dec 20 '18 at 22:17
Zest
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Borrowing heavily from Dennis Kaarsemaker's answer:
PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
PS1='u@h $_abbrev_pwd> '
The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:
- the output of a sed command:
$(sed -e ... <<< ...) - a forward slash
/ - the "current" directory:
$(basename "$PWD")
The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):
- replace any appearance of your "$HOME" directory with a tilde, and
- replace any path element (forward slash, a captured single character
., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with thegflag. I've used:as thesedsearch & replace delimiter instead of the common/, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.
Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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%2funix.stackexchange.com%2fquestions%2f490222%2fbash-prompt-configuration%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
Borrowing heavily from Dennis Kaarsemaker's answer:
PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
PS1='u@h $_abbrev_pwd> '
The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:
- the output of a sed command:
$(sed -e ... <<< ...) - a forward slash
/ - the "current" directory:
$(basename "$PWD")
The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):
- replace any appearance of your "$HOME" directory with a tilde, and
- replace any path element (forward slash, a captured single character
., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with thegflag. I've used:as thesedsearch & replace delimiter instead of the common/, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.
Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.
add a comment |
Borrowing heavily from Dennis Kaarsemaker's answer:
PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
PS1='u@h $_abbrev_pwd> '
The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:
- the output of a sed command:
$(sed -e ... <<< ...) - a forward slash
/ - the "current" directory:
$(basename "$PWD")
The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):
- replace any appearance of your "$HOME" directory with a tilde, and
- replace any path element (forward slash, a captured single character
., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with thegflag. I've used:as thesedsearch & replace delimiter instead of the common/, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.
Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.
add a comment |
Borrowing heavily from Dennis Kaarsemaker's answer:
PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
PS1='u@h $_abbrev_pwd> '
The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:
- the output of a sed command:
$(sed -e ... <<< ...) - a forward slash
/ - the "current" directory:
$(basename "$PWD")
The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):
- replace any appearance of your "$HOME" directory with a tilde, and
- replace any path element (forward slash, a captured single character
., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with thegflag. I've used:as thesedsearch & replace delimiter instead of the common/, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.
Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.
Borrowing heavily from Dennis Kaarsemaker's answer:
PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
PS1='u@h $_abbrev_pwd> '
The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:
- the output of a sed command:
$(sed -e ... <<< ...) - a forward slash
/ - the "current" directory:
$(basename "$PWD")
The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):
- replace any appearance of your "$HOME" directory with a tilde, and
- replace any path element (forward slash, a captured single character
., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with thegflag. I've used:as thesedsearch & replace delimiter instead of the common/, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.
Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.
answered Dec 28 '18 at 17:27
Jeff Schaller
38.8k1053125
38.8k1053125
add a comment |
add a comment |
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.
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%2funix.stackexchange.com%2fquestions%2f490222%2fbash-prompt-configuration%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