Jump to content
V.T. Eric Layton

Custom Bash Prompts

Recommended Posts

I got bored earlier today and tweaked the prompt on all my distros to look like these...

 

In Slackware:

 

vtel57_Slackware~:$

root_Slackware~:#

 

In Debian:

 

vtel57_Debian~:$

root_Debian~:#

 

In CentOS:

 

vtel57_CentOS:~$

root_CentOS:~#

 

Et cetera... you get the idea.

 

The ~ signifies the /home directory for the user. If I move to say /etc/X11, it would look like this:

 

vtel57_Slackware/etc/X11:$

root_Slackware/etc/X11:#

 

Cool, huh? :rolleyes:

 

I used a combination of Bruno's Tweaking the Prompt tip and another script found elsewhere to colorize the root prompt. I had to tweak the .bashrc in /home/vtel57 and the .bashrc in /(root) to achieve this. Here are the mods I used:

 

/home/vtel57/.bashrc

 

# /home/vtel57/.bashrc# custom promptPS1="\u_\w:$ "

 

/(root).bashrc

 

# ~/.bashrc: executed by bash(1) for non-login shells.export PS1='\u_\w\:$ '# root prompt = redTERM_USER_HOST_COLOR='0;31m'TERM_PATH_COLOR='0;31m'TERM_PROMPT_COLOR='0;31m'TERM_USER_HOST='\u_'TERM_PATH='\w'TERM_PROMPT='\$'export PS1=\'\[\e['${TERM_USER_HOST_COLOR}'\]'${TERM_USER_HOST}'\[\e[m\]'\'\[\e['${TERM_PATH_COLOR}'\]'${TERM_PATH}'\[\e[m\]'\'\[\e['${TERM_PROMPT_COLOR}'\]:#\[\e[m\] '

 

Where you see "", I inserted my distribution name.

 

:rolleyes: Yup... bored.

Share this post


Link to post
Share on other sites

Very cool!!! I imagine that helps with all the distros you run on your machine. So you added that to the ~/.bashrc in all your partitions for user and root?Thanks

Share this post


Link to post
Share on other sites

Yup... and yes, it does help. Sometimes, I boot into a distro to tweak/update or whatever and forget where I'm at after a while. The red root prompt also alerts me that I'm root. It's a hard-to-miss visual reminder.

Share this post


Link to post
Share on other sites

You can also title your terminal windows.For instance, try

echo -ne "\033]0;Free Space\007";watch df

and you should get a terminal window titled Free Space.You can also put this into a function for use in a script:

title() {	echo -ne "\033]0;${1}\007"}

and then when your script can set the title as needed like this:title "Pass 1"(commands for pass 1)title "Pass 2"(commands for pass 2)I use this when I encode video so that I know generally where it is in the process.Tested on Ubuntu 64 bit - I assume that this should work on most of the others as well.

Edited by jimg

Share this post


Link to post
Share on other sites

Thats pretty cool Jim. If I used window titles on my terminal, I would definitely use these scripts. Saved in Documents for future use. Thanks

Share this post


Link to post
Share on other sites

Very cool!!! I imagine that helps with all the distros you run on your machine. So you added that to the ~/.bashrc in all your partitions for user and root?Thanks

 

By the way, custom user prompts and custom-colored root prompts that state the operating system are VERY handy when sshing. For example, if I'm on my shop system in Slackware and I ssh into my main system that is booted to Arch, my user prompt will change from vtel57_slackware~:$ to vtel57_arch~:$. It's even better with the red root prompt because you don't want to be making changes as root in an ssh environment only to realize later that you edited the file in your primary booted OS by accident.

  • Like 1

Share this post


Link to post
Share on other sites

I do the same except I have my prompt showing different hostnames since I use the same username on most of my machines.

Share this post


Link to post
Share on other sites

That would work even gooder, actually. All my systems have unique host names also. Hmmmm... something to think about. :yes:

Share this post


Link to post
Share on other sites

Is DarkStar a Slackware machine? ;)

 

No but that is where I originally got the name. The hostname used to be a Slackware machine years ago but now it is my Arch machine on Linode VPS. I mostly use planet names for my other machines:

 

Cerbrus (main rig)

Neptune (Laptop)

Pluto (eeepc)

MiniMe (HP Mini)

Nitro (phone)

Mars (N810)

Baphomet (router/server)

 

The only ones I have not named yet are my HP Touchpad and my Nexus 7.

 

Oh, I forgot about my other laptop: Saturn

Share this post


Link to post
Share on other sites

Just gave my Nexus 7 a hostname:

 

Athena:

The goddess of wisdom, warfare, battle strategy, heroic endeavour, handicrafts and reason. According to most traditions, she was born from Zeus's head fully formed and armored. She was depicted crowned with a crested helm, armed with shield and a spear. Her symbol is the olive tree. She is commonly shown accompanied by her sacred animal, the owl.

http://en.wikipedia.org/wiki/Athena

Sorry to (sorta) get off topic...

  • Like 1

Share this post


Link to post
Share on other sites

Cool! I have such unimaginative host names:

 

ericsbane05 - my main system

ericsshop02 - my shop system

ericslaptop01 - my Dell Inspiron 1521 home office laptop (the one you gave me :) )

jennieslaptop - the Dell Latitude D410 that my niece gave me

Share this post


Link to post
Share on other sites

Inspired by Josh's suggestion about using hostnames...

 

My new prompts:

 

vtel57@ericsbane05|Slackware~:$

root@ericsbane05|Slackware~:#

 

vtel57@ericsbane05|Arch~:$

root@ericsbane05|Arch~:#

 

vtel57@ericsslaptop01|Slackware~:$

root@ericslaptop01|Slackware~:#

 

vtel57@ericsshop02|Slackware~:$

root@ericsshop02|Slackware~:#

 

:)

Share this post


Link to post
Share on other sites

Inspired by Josh's suggestion about using hostnames...

 

My new prompts:

 

vtel57@ericsbane05|Slackware~:$

root@ericsbane05|Slackware~:#

 

vtel57@ericsbane05|Arch~:$

root@ericsbane05|Arch~:#

 

vtel57@ericsslaptop01|Slackware~:$

root@ericslaptop01|Slackware~:#

 

vtel57@ericsshop02|Slackware~:$

root@ericsshop02|Slackware~:#

 

:)

 

Looks good but a bit long. If I were you, I would use something like:

 

vtel57@laptop|Slack~:$
vtel57@laptop|Arch~:$

 

vtel57@shop1(2)|Slack~:$
vtel57@shop1(2)|Arch~:$

 

No point in the Eric part as you already know who's machines they are :hysterical:

Share this post


Link to post
Share on other sites

On all my systems I "fix" my bash prompt to be blue for normal user and red for root. Nothing fancy, but an effective visual clue to remind me not to do something stupid. When I see red, I stop and think before issuing a command.

Share this post


Link to post
Share on other sites

Yeah, that's true. It's best to learn from others' mistakes, though. :yes:

Especailly since I don't make any

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...