Let's talk about your ugly prompt

We all have a bash prompt or PS1. Some people like to make them a bit fancy. :raised_hand_with_fingers_splayed: For those folks, there are some handy sites on the web. Some are a little better than others. Some might have an element or two that another one does not have. Being able to drag and drop and rearrange elements and put them in different order, on opposite sides of the terminal, or add colors is a big deal. A note about colors. The pallet of colors is set by the theme of the terminal emulator. Change the theme and the prompt colors will also change.

Here is a quick look at mine. It is split to two lines. I have a different user color for mine and root. The one for root is optional, but hey why do it part way?

# Sourced by .bashrc to create my PS1 prompt
# The one in /root has a different color for the user. I just rem out the one I don't need with a #.


#2 line color prompt (root)
#export PS1="ā”Œā”€ā”€[\[\e[31m\]\u\[\e[m\]@\[\e[36m\]\h\[\e[m\]] \d, \[\e[36m\]\T\[\e[m\] [\e[31m\]\w\[\e[m\]] \nā””ā”€ā”€[ <\[\e[5;31m\]\\$\[\e[m\]> "

#2 line color prompt (user)
export PS1="ā”Œā”€ā”€[\[\e[1;33m\]\u\[\e[m\]@\[\e[36m\]\h\[\e[m\]] \d, \[\e[36m\]\T\[\e[m\] [\e[1;33m\]\w\[\e[m\]] \nā””ā”€ā”€[ <\[\e[1;5;33m\]\\$\[\e[m\]> "

Yes, it looks complicated, but there are sites to help you do this.

https://ezprompt.net/

https://omar.io/ps1gen/

There arenā€™t any real how-toā€™s for using these sites. They are each different. Just get in there and play with them and see what you like.

These are just for bash. If you are using a different shell, like fish or zsh, this will not apply to you.

how do you feel about stuff like oh-my-bash?

1 Like

They are fine, but use resources. I decided to just go with a simple PS1. Sometimes less is more.

I use zsh, and prezto. Zsh is way better than bash, while still being compatible.

1 Like

After playing with plenty incl. oh-my-* and few new ā€œfancyā€ terms Iā€™d gone back to simple

<path>/
[exitcode!=0 ]#|$ _

Simply there is nothing else thatā€™s needed in it. I may add additional color/text stuff for the remote servers (root/user, prod/staging/test/ā€¦) but not for local.

Lately I just change colors if I get must-mess-with-the-prompt urge again :wink:

1 Like

I used to use ZSH and Fish, but I came back to simple.

2 Likes

I feel itā€™s great for people like me who are lazy and just want something with a ton of options and features built-in that I can simply uncomment to enable at will. I find the ā€œlsā€ aliases most useful, and I do also enjoy setting the theme to ā€œrandomā€ to cycle through the myriad of themes.

While on the topic of sprucing-up your prompt, if youā€™re using Konsole, you can have it load your preferred tab layout by first saving it as a file to your home directory:
Hamburger Menuā€“>Moreā€“>Viewā€“>Save Tab Layoutā€¦ {give it a filename}

Once saved, you need to configure Konsole to load it at startup:
Right click Application Launcherā€”>Edit Applicationsā€¦ā€“>Systemā€“>Konsoleā€“>Command-Line Arguments:

--layout /path/to/your_konsole_tab_layout.json

Save and close your edit.
Now when you open Konsole, it will open it with your custom tab layout.

2 Likes

Thanks, @WilsonPhillips I was thinking about this when I saw some of the coloration in your prompts earlier today. I use BLE and itā€™s very helpful, but doesnā€™t change a lot of the aesthetic of the prompt. Iā€™m going to have to explore these.

1 Like

This was such a fun experiment. Iā€™m a bash-first user but I like the way customizations look in ZSH, etc. (but I still want bash, lol). Anyway, here is the code I came up with:

PROMPT_COMMAND="PS1_CMD1=$(hostname -I | awk '{print $1}')"; PS1='\[\e[38;5;88m\]ā”\[\e[0m\] \[\e[38;5;34;1m\]\u\[\e[0m\] \[\e[38;5;208m\]@\[\e[0m\] \[\e[38;5;33;4m\]\h\[\e[0m\]-----------------\[\e[38;5;16;100;4;53m\]${PS1_CMD1}\[\e[0m\]-----------------\[\e[38;5;34m\]\@\n\[\e[38;5;88m\]ā”–\[\e[0m\] \[\e[38;5;208m\]\w\[\e[0m\] \[\e[38;5;39m\]\$\[\e[0m\] ]'

I used the Bash Prompt Generator, thanks @WilsonPhillips , but noticed that it was using an IP route lookup to cloudflare (1.1.1.1) and who wants that happening every time one opens a terminal? So I modified the command to do a simple hostname lookup and a cut it down to the first return.
And this is what it looks like:


You may find yours looks a little different based on what kind of font you use. The font Iā€™m using is Fira Code (demi-bold), which presents very well in the terminal.

2 Likes

I have not even looked at what font OpenMandriva defaulted with.

Not sure how the cloudflare lookup got there. I just pasted the links from brave search.

I should have been clear, I apologize. I have my local IP appear on the top-line, and it was using a query to 1.1.1.1 to determine my local IP. I found that very strange. Anyway, I was able to modify the variable! Gotta love linux.