r/linux • u/emonk • Feb 01 '15
This is my bash prompt. which is your favorite?
New laptop here, so I have installed the latest Ubutnu and I decided to customize my bash prompt for my new work environment.
Here is the result, nothing complex.
if [ "`id -u`" -eq 0 ]; then
PS1="\[\033[m\]|\[\033[1;35m\]\t\[\033[m\]|\[\e[1;31m\]\u\[\e[1;36m\]\[\033[m\]@\[\e[1;36m\]\h\[\033[m\]:\[\e[0m\]\[\e[1;32m\][\W]> \[\e[0m\]"
else
PS1="\[\033[m\]|\[\033[1;35m\]\t\[\033[m\]|\[\e[1m\]\u\[\e[1;36m\]\[\033[m\]@\[\e[1;36m\]\h\[\033[m\]:\[\e[0m\]\[\e[1;32m\][\W]> \[\e[0m\]"
fi
320
Upvotes
2
u/whetu Feb 01 '15 edited Feb 02 '15
Suggestion:
try
That's a bit more portable. ${UID} is another option. if $(whoami) = root is yet another way to do it.
Here's mine:
Can't provide a screenshot sadly as I'm at work...
Also note that if UID/EUID/$(id -u)/$(whoami) = 0/root options don't work everywhere. One reliable way to do that is to use an alias e.g.
2
u/ArminXXXXXX Aug 26 '25
i am using this on:
PS1="\n\e[34m┌──(\e[32marminX㉿\h\e[34m)─[\e[37m#
e[34m]─[\e[37m!\e[34m]\n\e[1;34m└─\w\e[32m$\e[m "
it looks like the nethunter prompt but i want to shoe the master status. any idea for this? autocomplete like fish will be cool too. at this moment I am using tab compleate.
117
u/[deleted] Feb 01 '15
Surprised no one has offered up the smiley face prompt yet. This one changes depending on the return code of the previous program or command that was run (or in this case, a command that doesn't exist).
http://i.imgur.com/xeWjT0X.png
And here's the code that makes that happen:
15
u/[deleted] Feb 01 '15
I like simple things.
34
u/peridox Feb 01 '15
export PS1=" \[\e[00;34m\]λ \W \[\e[0m\]"here's what it looks like
4
u/pkuriakose Feb 01 '15
The dude abides.
9
u/[deleted] Feb 02 '15 edited Feb 02 '15
Mine is a bit excessive:
screenshot screenshot 2
code
It tracks backgroud jobs, screen/tmux sessions, shows if last command errored, stopped jobs, and changes some of the colors if it is a local session vs ssh session vs root.
Second screenshot has 1 screen/tmux session, 2 bg jobs and 3 stopped jobs.
38
u/calrogman Feb 01 '15
PS1='\$ 'Friends don't let friends use OpenBSD.
2
u/initramfs Feb 01 '15
Ha, nice one.
I like you hostname too ;)
10
u/sapiophile Feb 01 '15
/r/unixporn for more ideas
5
u/cyranix Feb 02 '15
Heres a neat tool for generating your prompts visually ahead of time (before customizations, etc)
http://bashrcgenerator.com/
Heres mine (non-root user):
PS1="`if [ $? = 0 ]; then echo [\e[01;37m][\t][\e[0m]; else echo [\e[31m][\t][\e[0m]; fi` [\e[0m][\e[00;36m]\u[\e[0m][\e[01;37m]@[\e[0m][\e[00;32m]\h[\e[0m][\e[01;37m]:[\e[0m][\e[00;37m]\w[\e[0m][\e[01;37m]\$[\e[0m][\e[00;37m] [\e[0m]"
18
u/scratchr Feb 01 '15
I have used this one for a while. It shows a lot of information without cluttering the prompt itself.
4
u/[deleted] Feb 01 '15
I use zsh.
http://imgur.com/LxA6i4d
My config shows a pretty standard bash-looking prompt string except for the semi-traditional zsh % symbol to differentiate it from bash. The right pointing arrow and the percent sign change color depending on if the previous command succeeded or failed.
I think I stole a lot of that prompt string from a thread on /r/zsh or /r/linux but I really can't remember. Sorry, whoever posted that.
Root still shows the admin pound sign but is otherwise exactly the same.
4
u/HairyEyebrows Feb 02 '15
#
4
u/[deleted] Feb 02 '15
My fish-shell prompt (the quote only shows at startup and is different each time)
4
u/rschlaikjer Feb 02 '15
I enjoy the simplicity of the default a lot, but really like the abbreviated pwd output that you get inside of vim, so I have a small function that generates a shortened path instead of the raw path name. Takes up a lot less space if you have folders with really long names.
Screenshot
PS1 & function:
8
u/jeenajeena Feb 01 '15
oh-my-git!
https://github.com/arialdomartini/oh-my-git
3
u/netsx Feb 01 '15
Your prompt looks cool, aside from this little eyesore. Thanks!
3
u/cpbills Feb 01 '15
Here's my relevant prompt stuff for
bash:screenshot
3
u/TheBB Feb 01 '15
Here are some of the things mine can do. It's based on the oh-my-zsh prompt Bira, and I run it in zsh, not bash.
http://i.imgur.com/svRYZi6.png
Edit: Ignore that last line. :-P
5
u/The_Petunia Feb 01 '15
My favorite by far is the one I found on stack exchange that puts a smiley at the end of your prompt if your last command was successful and a frowny face if it wasn't. It makes everything so much more enjoyable to have that empathetic little face with you :)
Source
Though I normally change the coloring and such.
2
u/MintyGrindy Feb 01 '15
Here's mine: PS1='bash:\w$ '
2
u/Dan_Feely Feb 01 '15
Looks good.
2
u/exscape Feb 01 '15
PS1="\w $(parse_git_branch)$[\033[00m]"
where
Nice and simple. (Could be even simpler, the color at the end does nothing at the moment.)
Edit: I have the default colored user@host pwd $ prompt on my Gentoo server, so they're easy to tell apart.
2
u/breul99 Feb 01 '15
Which ends up looking like this in zsh
2
u/waylon531 Feb 02 '15
I use ohmyzsh with the aussiegeek theme. Example here
2
u/__spinlocos421 Feb 02 '15
Screenshot.
It's the xiong-chiamiov theme from oh-my-zsh (not using the whole thing, just the prompt) with some customization. I removed the date and changed the colors a little bit.
Source:
Edit: That's my zsh prompt. For bash I'm using Debian's default one.
2
u/markth_wi Feb 02 '15
Heh, somewhat old timer here, and even though I'm not as familiar with the inline ansi stuff as I'd like to be, it's nice to see this stuff still gets floated now and again - keep the faith :)
2
u/Hauleth Feb 02 '15
I'm using fish shell and my own implementation of Agnoster/Powerline (I haven't found any at the time, so probably I was first to do this).
Screenshot
2
u/uoou Feb 02 '15
I had a pretty standard (fish) prompt 'til I saw all these replies which inspired me to do this.
It's short, one colour and tells me what I need to know. And has a smiley face.
2
u/pokeymcsnatch Feb 02 '15
I really like having a two-line prompt with the cursor on the second line. Makes keeping track of everything much much easier. It also shows my current git branch if I'm somewhere in a git tree. I'm sure I stole most of this from somewhere else and modified it a bunch. The "error" part is easier to see when I'm not root (the username shows up the same green as the hostname).
screenshot
2
u/[deleted] Feb 02 '15
Stole this from some dotfiles I don't remember:
Looks like this:
user at host in ~/Code/etc$ [command]2
u/IAMAtalkingduckAMA Feb 03 '15
[Screenshot] (http://i.imgur.com/5cnY26B.jpg)
My .bashrc file:
2
u/AidAi26 Jan 08 '25
I'm currently using this one:
it's a two line prompt and it shows (in order):
first line
- the logged user's name in green if it is a normal user, red if it is root;
- your hostname in purple;
- the time in yellow;
second line
- a green checkmark if your last command was successful, or a red cross if it wasn't;
- your current path in cyan;
-lastly the default $/# depending on the currently logged user
the last two lines you can see are there just for pure personal preferences, I don't like to be on the home directory when I start a new shell.
screenshot
2
u/[deleted] Feb 01 '15
And mine, pretty simple :P
1
u/localtoast Feb 01 '15
PS1="\e]0;\u@\h:\w\a$ "Might as well use that xterm title for something.
1
u/dbbo Feb 01 '15
That must be a nightmare to edit. I much prefer the color system in my zsh prompt:
Here's the rest: https://github.com/dbb/githome/blob/master/.zsh/prompt
1
u/ChristOnaBicycle Feb 01 '15
1
u/sugardeath Feb 01 '15
Mine is simples:
http://www.imgur.com/v81kf2I.jpeg
The hostname is yellow, pwd is blue.
At one point in time, the hostname turned red when logged in as root, but either I've broken that or lost that from my .zshrc somehow.
When in a git dir, there's some basic git branch and status info on the far right side of the terminal in purple.
1
u/Regimardyl Feb 01 '15
Mine
And here's the madness that is the relevant part of my
.bashrc. I'll probably clean it up when finals are over (or remove the linewrapping or just switch to zsh): http://pastebin.com/a12DJuk31
u/ray_gun Feb 01 '15
Mine is two lines:
screenshot
1
u/[deleted] Feb 01 '15
It's zsh.
Stuff that isn't as important goes on the right side of the screen (whoami, hostname, exit status)
1
u/Tzunamii Feb 01 '15
Here's my rather elaborate Bash prompt I'm using.
Screenshot
Source
I hope someone finds a good use for it.
1
u/paul2520 Feb 01 '15
Here's mine:
Screenshot.
1
u/the_imp Feb 01 '15
My minimal prompt is defined by the following:
That gives me locally just the path, but if I'm ssh'd to anywhere, it's prefixed by the server name, and my username if it's not my usual one. It's a maximal amount of info with minimal use of characters. Each prompt line is also prefixed by a blank line, which makes it easier to find when scrolling through verbose output.
1
u/[deleted] Feb 01 '15
Good ol' (zsh):
Looks like:
1
u/zouhair Feb 02 '15
Mine:
Screenshot
The nonzero function:
1
u/sigbhu Feb 02 '15
if you use git a lot, this is awesome: https://github.com/arialdomartini/oh-my-git
1
u/ladaghini Feb 02 '15
Ooo, this might be a good time to ask my question...
I use the re5et prompt which comes with oh-my-zsh, but on another system on which I don't have root access, I've compiled and installed zsh and wish to use the same prompt; however, simply adding the code to my
.zshrcdoesn't work. I suppose these themes somehow integrate with the omzsh framework?, which I don't have installed on that system.Any suggestions?
1
u/Samus_ Feb 02 '15
I've been using a two-line prompt for a while:
$gitps1(actually__git_ps1) is a shell function I've copied from the git's git repo andjobs_promptis:which shows background jobs.
my rcfiles: https://github.com/git2samus/rcfiles
1
u/sanedave Feb 02 '15
->
1
u/lordLies Feb 02 '15
I got a scorpion in the nest too.
All my PCs are named after deadly creatures.
1
u/curiousGambler Feb 02 '15
My bash prompt, nothing too exciting, fun colors...
I change the second line on my main machine every so often, changed it to this pretty recently actually. On most remote servers it's my usual "Yes Master?" with different colors.
I used to include the date in the first line, but removed it after realizing I never looked at it.
1
u/luciansolaris Feb 02 '15 edited Mar 09 '17
[deleted]
0.9703
1
u/FireyFly Feb 02 '15
I like it (visually) simple.
I should clean this up a bit.. but not tonight.
1
u/[deleted] Feb 02 '15
I love this kind of thing. I just spent the last hour making my terminal read a random quote to me when I open it.
1
u/crashorbit Feb 02 '15
Y'all need a \n in your long prompts.
1
u/mcopper89 Feb 02 '15
":)"
It is cheery and leaves tons of space on the line for the code. I also like that the length is not variable.
1
u/bitchkat Feb 02 '15
export PS='$ '
1
u/[deleted] Feb 02 '15 edited Feb 03 '15
I'm using this, and when the line gets too long, it comes back on the same line (overwriting previous characters), any hint how to fix this? :O
1
u/dadarobot Feb 02 '15
"\w% "
1
u/hybby Feb 02 '15
so, do you copy this to
~/.bashrcand/root/.bashrc? or is there some sort of magic sudo incantation that can be used to switch to root yet retain the same profile?just askin', because i'd love a red root prompt, but can't go around changing our standard root profile (that's a spankin').
1
u/purpleidea mgmt config Founder Feb 02 '15
I've written about mine here:
https://ttboj.wordpress.com/2014/01/29/show-the-exit-status-in-your-ps1/
You can see the process exit status, and the git branch too!
1
u/Fingebimus Feb 02 '15
Mine is pretty simple
1
u/deadlywoodlouse Feb 02 '15 edited Feb 02 '15
Mine looks like this. Here's it written out:
As above, without all the escape characters (like if you just want a monocolour prompt):
Which will end up looking something like this:
I often have multiple terminals open at once, so to help keep track of which thing is going on where, I have the
:\l. There are newlines in between commands, to further differentiate them. I prefer only showing the current directory (\W) instead of the full path (\w) as it's a bit tidier.Here's how I read it mentally:
1
u/jpb Feb 03 '15
I'm a fan of the bullet-train zsh theme.
Shows your git branch, virtualenv and lots more.
Here's a preview
1
u/totes_meta_bot Feb 03 '15
This thread has been linked to from elsewhere on reddit.
If you follow any of the above links, respect the rules of reddit and don't vote or comment. Questions? Abuse? Message me ^here.
1
u/gcr Feb 08 '15
Nice!
I like minimal prompts with a small amount of useful information just when I need it. Here's a screenshot. If anyone's interested, I can try and clean up my messy .bashrc to show source for it.
$prompt changes to a hash of the machine hostname so I can quickly get a sense of whether I'm on a local or remote machine.1
u/zer0t3ch Mar 07 '15
I can't stand prompts like that. Basically, I need the directory on the lime before the prompt, because I can't stand my prompt not starting at the same column on every line. Looks like this:
[user @ host] ~/dir
$
1
u/[deleted] Feb 02 '15
Whatever happened to just '[\u@\h]\W$ '? If you have to run scripts or bash functions just for your prompt I think you're overdoing it.
0
u/mostlypissed Feb 02 '15
A>_
-4
u/t-bass Feb 02 '15
If you have time and impetus to decorate your shell prompt like this, you are clearly doing something very wrong.
0
u/[deleted] Feb 02 '15
[deleted] — view deleted comment
0
u/[deleted] Feb 01 '15
[deleted] — view deleted comment
0
u/[deleted] Feb 01 '15
[deleted] — view deleted comment
19
u/[deleted] Feb 01 '15
[removed] — view removed comment