I see many people at work with very complex prompt shells. These include the username, hostname, active git branch and git changes, the current Python virtualenv, the npm/nodejs version, etc.
My own prompt is quite quaint in comparison:
:) ~$ dont_exist
bash: dont_exist: command not found
:( ~$
Just a smiley to indicate the exit status of the previous command (not shown here: happy smiley in green, frowny in red), the current workdir director, and a $/# indicator for regular user/super user.
What do your own shell prompts look like?
P.S.: Here’s the code that generates my prompt.
generate_prompt() {
local exit="$?"
local reset='\[\e[0m\]'
local red='\[\e[1;31m\]'
local green='\[\e[1;32m\]'
local status
if [[ $exit -eq 0 ]]; then
status="${green}:)${reset}"
else
status="${red}:(${reset}"
fi
PS1="${status} \w\$ "
}
export PROMPT_COMMAND=generate_prompt
There was a recent thread on this a few months ago, if you want to see some more answers.
What does your shell prompt look like?
I’ve started using Starship and I’m pretty happy with last few weeks.
https://github.com/starship/starship
My shell prompt is quite involved, but I’m using fish, so I’m not gonna paste the whole code here.
But I’d like to share one change in approach, that I found a game changer:
Make it two lines.
The more stuff you put into your prompt, the longer it gets, so what I do is that I have one line with the path, git info etc and the second line just starts with
➤
. So my actual prompt is always on the very left, no matter how long the path. Which also means I don’t have to shorten the path or other things I’ve seen people do.For example right now, it looks like this:
The git status on the top right means: 25 files staged, 11 changed, 1 untracked. The
[2]
is the return code of the last execution.Of course there’s lots of colors. :)
That’s also my approach to command line prompt, with the difference that I use Bash (but recently I have been exploring fish as a daily driver as well). I can’t recommend it enough, especially given the fact that current monitors allow for giving up one line like that.
Similar here in fish:
I only did a few small things after switching to fish:
~/.config/fish/fish_variables
(Set Vi mode)~/.config/fish/config.fish
(ctrl-f to accept autocomplete suggestions in Vi mode)Install pure
~/.config/fish/conf.d/pure.fish
:Mine is quite simple too. It includes my username, hostname,
[env]
(when inguix environment
), and a fish-like shortened form of the current working directory.So, for instance, when in
~/src/git/guix
, the prompt looks like this:And when in a
guix environment
, like so:The relevant bits from my bashrc:
Mine is pretty close to that:
Using a colon instead of a space means that I can directly copy and paste it into an
scp
orrsync
command in another shell.Oh that’s clever.
This is the prompt I have been using for years (I am using Fish):
It looks like this in my home directory:
And like this in another directory:
I use
zsh
I don’t update my environment very much; I’ve taken my basic UI (Window Maker,
zsh
,xterm
, Emacs, a few other things) with me across multiple Linux distros. It’s old enough that I’m pretty sure it predates emoji support in widely-available terminal fonts, for example.I think I last modified mine in 2003 or something? I remember choosing zsh at the time for the simple reason that it supported right-aligned prompts. I’m not sure if the hostname-into-awk nonsense predates the %m escape code, or if I simply was unaware of it at the time.
I never liked shell prompts of varying lengths. Mine are always two lines, where the second is short, and I find this much nicer to read, because I only care about the information in the prompt some of the time.
my dotfiles
The :)/:( exit status is much appreciated, very cute.
On some systems, it’s just
\$
, but typically:\u@\h \W \$
IKMPS (I keep my prompt simple):
(
vps
is not a real hostname, I’ve actually hardcoded it to a string to avoid DO’s default hostname).In my experience, adding the time to your shell is probably one of the more important things you can have.
When the world is falling down around you at 2:45AM and you can barely think straight, scrolling up and seeing what you did is great, but knowing when you did it is essential.
I use pure, a ZSH prompt. It tells me information about the git repository I’m in, too.
For example:
While I haven’t yet gotten around to implementing the same features in my rash prompt, in Zsh I have a somewhat unique prompt.
The most unique feature is path coloring based on ownership and permissions. In general my philosophy on prompts is that I want all info displayed that may be relevant. To that end, I display git info when in a git repo (branch name with options for coloring the name based on regexp, whether or not there are uncommitted changes or changes in submodules, and the number of commits ahead/behind upstream), I check environment variables and display the hostname when inside ssh or tmux, I check my username and display it if it is not the username I usually use, I display the return code of the previous command if it was not 0, etc.
So far for Rash I’ve really only implemented getting git info (which is frequently the info I care most about), but I plan to add libraries to make a lot more situational info available, with timeouts everywhere so my shell doesn’t lag in big repositories or remote file systems.
My overly detailed prompt is available at https://github.com/gioele/bashrc.d/blob/master/prompt.
A couple of examples:
gioele@host:~/Projects/pw [master * u=]$
(more or less the usual__git_ps1
+ colors)gioele@remote:/srv/dir (ssh)$
(Thessh
part is colored. Different colors for different hosts.){rb,py,nod}env
has been activatedgioele@host:~ (ruby 2.6.2)$
gioele@host:~ (errcode: 127)$
$
on its own line)My prompt is still
PS1="\$ "
. It’s#
when I’m root and$
when I’m not.pwd
tells me the directory I should know I’m in. All that git stuff, oddly, is accessible under thegit
command.at work:
at home:
I’ve never really been able to find value in the more elaborate prompts, probably because my terminal usage is : open, run command, close. I also don’t ssh around, or do much git stuff from the command line, so ¯_(ツ)_/¯.
Currently
so for example
It used to be just the hostname, but since I’ve been working more with remote servers, I added the hostname too. Recently I’ve been running the wrong commands on the wrong machine, making me consider some colour, calculated by the hash of the hostname or something, but I’m not sure if that will help that much either. Has anyone got any tips on how they handle this issue?
I just use whatever’s configured on what are mostly VPSes. Dotfiles take effort. I’ve gotten used to vanilla vim.
I’m currently using fish and use the following prompt at home:
https://gist.github.com/xnuk/452ae61e077f886471b5
At work my tooling/dot files have gotten out of sync and it looks like I’m using this:
https://github.com/fishpkg/fish-prompt-metro
I’ve been meaning to look at and try out new prompts again. Thanks for starting a new thread.
https://github.com/nhooyr/dotfiles/blob/062e9fe7f6408a8e3d566f7f56db80e4dacd6eba/fish/functions/fish_prompt.fish
Looks like this:
benoncoffee@hostname 》
In bold green text, and the current path in white, on the right.
The prompt itself is just an arrow. Different colors for different hosts.
Fish has a “right prompt”. It disappears if you type a long command and it reappears if possible.
Now that I’m thinking about it, I never rely on the display of the current git branch. I should remove it.
It’s dynamic, and I use ksh
I try to keep my ZSH prompt fairly simple, but context driven.
When I am on my local machine, it looks like this:
The
%1~
part shows only the current dir name or~
if curdir is$HOME
.When USER is not my normal username :
When a non-local host (eg ssh):
When USER is not my normal username, AND non local host (ssh) :
When root, the
%
turns to#
, and the#
is red:I also have RPS1 set for vcs info:
helpful ref: zsh prompt expansion
Work desktop:
Work servers:
I’m unable to function without
__git_ps1
. I have a simplehostname:curdir>
, with hostname in red and the basename of the current directory (and git info if applicable) in cyan:\[\e[0;31m\]\h\[\e[0m\]:\[\e[0;36m\]\W$(__git_ps1 "(%s)")\[\e[0m\]>
Without colors that’s
\h:\W$(__git_ps1 "(%s)")>
At work I added a little bash function to tell me how long the last command took if it took more than a second, but it’s not as useful as I expected.
it looks like:
oh-my-zsh default. It has everything I need and I don’t need to think about it.
I like the multi-line style, and I’ve got colors, too.
I use the rc shell, and I use a very simple prompt.
;
Then when you copy paste sessions without the output, you can run it again.
In my previous ZSH days, …
I mostly live in bash.
Here’s the string with the escapes:
Mine is
GenericUnixPrompt>
.Hostname in white, space, last 3 fragments of PWD in green (~ for $HOME), space, and then an underscore cursor. No nonsense. When I’m in a git repo I tack on some status at the end
Mine is:
Root prompt is the same except all white.
for me it is quite trivial actually (borrowed from gentoo)
` # gentoo prompt is excellent. set that up
}
prompt_gentoo_setup “$@” `
My prompt is based on the old RedHat default prompt:
At least in some terminals,
@
and:
are considered word characters, while[]
are not, so I can double-click on the prompt to copy my current location to the clipboard, for use withscp
orrsync
or other tools.I do have a bit of bash magic to limit the path length to 40 characters, though, since a too-long prompt gets a bit unwieldy.
Most importantly, though, I have my prompt change colour based on the hostname, which has more than once helped me avoid running a command on the wrong host by mistake.
;
export PS1=’$?$ ’
Rationale: typically this amounts to “0$ “, which is nice. The only required information is the status of the last command, which is on the shell variable $?. In the rare cases where I forget in which directory I am, running “pwd” is enough.
PS1="[\W \A] "
Answers the two crucial questions: where and when?
And its coloured with named colours, so it really looks like this: