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.

zsh "fishy" theme

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.

  • It did, thanks a lot and sorry for the delay. – Zest Jan 16 '19 at 23:34

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):

  1. replace any appearance of your "$HOME" directory with a tilde, and
  2. 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 the g flag. I've used : as the sed search & 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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