1. 28

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
    PS1="${status} \w\$ "

export PROMPT_COMMAND=generate_prompt
  1. 18
    (๑•ᴗ•)⊃━~━☆゚cd ∆
    1. 12

      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?

      1. 11

        I’ve started using Starship and I’m pretty happy with last few weeks.


        1. 5

          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:

          ~/Work/secret-project on master|→25!11?1
          [2] ➤

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

          1. 3

            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.

            1. 1

              Similar here in fish:

              ~/Code/somerepo master

              I only did a few small things after switching to fish:

              ~/.config/fish/fish_variables (Set Vi mode)

              SETUVAR fish_key_bindings:fish_vi_key_bindings

              ~/.config/fish/config.fish (ctrl-f to accept autocomplete suggestions in Vi mode)

              bind -M insert \cf accept-autosuggestion

              Install pure


              _pure_set_default pure_symbol_prompt "➫"
              _pure_set_default pure_symbol_reverse_prompt "➬"  # Shown in Vi edit mode
            2. 3

              Mine is quite simple too. It includes my username, hostname, [env] (when in guix 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:

              bandali@jirud ~/s/g/guix> 

              And when in a guix environment, like so:

              bandali@jirud [env] ~/s/g/guix> 

              The relevant bits from my bashrc:

              b_prompt() {
                  cwd=$(sed -e "s:$HOME:~:" -e "s:\(\.\?[^/]\)[^/]*/:\1/:g" <<<$PWD)
                  printf $cwd
              if [ -n "$GUIX_ENVIRONMENT" ]
                  PS1="\u@\h [env] \$(b_prompt)> "
                  PS1="\u@\h \$(b_prompt)> "
              1. 6

                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 or rsync command in another shell.

                1. 1

                  Oh that’s clever.

              2. 3

                This is the prompt I have been using for years (I am using Fish):

                function fish_prompt
                    if [ $PWD = $HOME ]
                        set directory '~'
                        set directory (basename $PWD)
                    set_color $fish_color_cwd
                    echo -n $directory
                    set_color normal
                    echo -n " \$ "

                It looks like this in my home directory:

                ~ $

                And like this in another directory:

                Downloads $
                1. 3

                  I use zsh

                  PS1='%n@%m %2d%% '
                  RPROMPT="%* %W"

                  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.

                  1. 1
                    PS1="`hostname | awk -F . '{print $1}'`%# ";

                    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.

                  2. 3

                    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.

                    dan@eddie pts/3 [~]
                    » screen
                    dan@eddie-screen pts/5 [~]
                    » cd dotfiles
                    dan@eddie-screen pts/5 ±1[m][master] [~/dotfiles]
                    » exit
                    dan@eddie pts/3 [~]

                    my dotfiles

                    The :)/:( exit status is much appreciated, very cute.

                    1. 3
                      1. 2

                        On some systems, it’s just \$ , but typically: \u@\h \W \$

                        1. 2

                          IKMPS (I keep my prompt simple):

                          (jobs:1) $ echo $PS1
                          (\u@\h)-(\t)-(\w)\n(jobs:\j) $

                          (vps is not a real hostname, I’ve actually hardcoded it to a string to avoid DO’s default hostname).

                          1. 2


                            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.

                          2. 2

                            I use pure, a ZSH prompt. It tells me information about the git repository I’m in, too.

                            For example:

                            ❯ ~
                            ❯ ~ cd Development/streisand
                            ❯ streisand master*
                            1. 2

                              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.

                              1. 2

                                My overly detailed prompt is available at https://github.com/gioele/bashrc.d/blob/master/prompt.

                                A couple of examples:

                                • Versioned git directory: gioele@host:~/Projects/pw [master * u=]$ (more or less the usual __git_ps1 + colors)
                                • When logged in via SSH: gioele@remote:/srv/dir (ssh)$ (The ssh part is colored. Different colors for different hosts.)
                                • When {rb,py,nod}env has been activated gioele@host:~ (ruby 2.6.2)$
                                • When the previous command did not exit with 0: gioele@host:~ (errcode: 127)$
                                • Once the prompt gets too long: ($ on its own line)
                                  gioele@remote:~/Projects/git-collab-guide [macos-screenshots * +3] (ssh)
                                1. 2

                                  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 the git command.

                                  1. 2

                                    at work:


                                    at home:

                                    cadey:cadey@kahless ~ ./rw
                                    1. 1
                                      ~ %

                                      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 ¯_(ツ)_/¯.

                                      1. 1


                                        [hostname] basename of pwd $ 

                                        so for example

                                        [bulbul] etc $ 

                                        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?

                                        1. 1

                                          I just use whatever’s configured on what are mostly VPSes. Dotfiles take effort. I’ve gotten used to vanilla vim.

                                          1. 1

                                            I’m currently using fish and use the following prompt at home:


                                            At work my tooling/dot files have gotten out of sync and it looks like I’m using this:


                                            I’ve been meaning to look at and try out new prompts again. Thanks for starting a new thread.

                                              1. 1

                                                benoncoffee@hostname 》

                                                In bold green text, and the current path in white, on the right.

                                                1. 1

                                                  The prompt itself is just an arrow. Different colors for different hosts.

                                                  ➤ true                                                            done 22:13:15 [gb master]
                                                  ➤ false                                                           done 22:13:18 [gb master]
                                                  return code 1 at 2019-09-22 22:13:19
                                                  ➤                                                                 done 22:13:19 [gb master]

                                                  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.

                                                  1. 1

                                                    It’s dynamic, and I use ksh

                                                    x220 | /home/ben
                                                    $ cd /git/whatever; false
                                                    x220 | /git/whatever [ master ] >>> 1 <<<
                                                    1. 1

                                                      I try to keep my ZSH prompt fairly simple, but context driven.

                                                      When I am on my local machine, it looks like this:

                                                      ~% echo $PS1

                                                      The %1~ part shows only the current dir name or ~ if curdir is $HOME.

                                                      When USER is not my normal username :

                                                      user@:~% echo $PS1

                                                      When a non-local host (eg ssh):

                                                      somehost:~% echo $PS1

                                                      When USER is not my normal username, AND non local host (ssh) :

                                                      user@somehost:~% echo $PS1

                                                      When root, the % turns to #, and the # is red:

                                                      root@somehost:~# echo $PS1

                                                      I also have RPS1 set for vcs info:

                                                      ~% echo $RPS1

                                                      helpful ref: zsh prompt expansion

                                                      1. 1

                                                        Work desktop:

                                                        ~$ echo "'$PS1'"
                                                        '\W\$ '

                                                        Work servers:

                                                        peach-dev01 ~$ echo "'$PS1'"
                                                        '\h \W\$ '
                                                        1. 1

                                                          I’m unable to function without __git_ps1. I have a simple hostname: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.

                                                          1. 1

                                                            PS1=”$(date +’%R’) $(basename "$(pwd)")$(if [[ "$(id -un)" == "root" ]]; then echo #; else print $; fi) “

                                                            <time> <folder>$

                                                            it looks like:

                                                            20:22 h$

                                                            1. 1

                                                              oh-my-zsh default. It has everything I need and I don’t need to think about it.

                                                              1. 1
                                                                  as unwind on MacBook
                                                                  in ~/Dropbox/yyyy-mm-dd/..
                                                                  $> fortune
                                                                FORTH IF HONK THEN

                                                                I like the multi-line style, and I’ve got colors, too.

                                                                1. 1

                                                                  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, …

                                                                  1. 1

                                                                    I mostly live in bash.

                                                                    19:16:43 kbjensen@obsidian:~/prog
                                                                    0 $ 

                                                                    Here’s the string with the escapes:

                                                                    PS1+="\[\033[38;5;32m\]\t \[\033[38;5;34m\]\u\[\033[38;5;37m\]@\[\033[38;5;31m\]\h\[\033[38;5;37m\]:\[\033[38;5;32m\]\w\n\[\033[38;5;34m\]\$? \[\033[38;5;37m\]\$ \[\033[0m\]"
                                                                    1. 1

                                                                      Mine is GenericUnixPrompt>.

                                                                      1. 1
                                                                        hostname pwd _

                                                                        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

                                                                        hostname pwd (branch) _
                                                                        1. 1

                                                                          Mine is:

                                                                          19-09-22 20:59:41 0  ~/src/lisp  > ls
                                                                          ^ Date    ^Time   ^$?  ^$PWD
                                                                          Purple    Yellow  White   yellow 

                                                                          Root prompt is the same except all white.

                                                                          export PROMPT="%{$fg_bold[magenta]%}%D%{$reset_color%} %{$fg_bold[yellow]%}%*%{$reset_color%} %? %{$fg_bold[yellow]%} %~ %{$reset_color%} > "
                                                                          export RPROMPT=
                                                                          1. 1

                                                                            for me it is quite trivial actually (borrowed from gentoo)

                                                                            ` # gentoo prompt is excellent. set that up

                                                                            prompt_gentoo_setup () {
                                                                                if [ "$USER" = 'root' ]
                                                                                    base_prompt="%B%F{$prompt_gentoo_root}%m%k "
                                                                                    base_prompt="%B%F{$prompt_gentoo_user}%n@%m%k "
                                                                                PS1="$base_prompt$path_prompt %# $post_prompt"
                                                                                PS2="$base_prompt$path_prompt %_> $post_prompt"
                                                                                PS3="$base_prompt$path_prompt ?# $post_prompt"


                                                                            prompt_gentoo_setup “$@” `

                                                                            1. 1
                                                                              λ(florian@parakeet ~) $ meh
                                                                              zsh: command not found: meh
                                                                              -127-(florian@parakeet ~) $
                                                                              • username is yellow on most machines
                                                                              • hostname is a different color on all my machines
                                                                              • error code is red.
                                                                              • zsh, config at https://github.com/winks/dotfiles
                                                                              • I hate multi-line prompts.
                                                                              1. 1

                                                                                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 with scp or rsync 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.

                                                                                1. 1


                                                                                  1. 1

                                                                                    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.

                                                                                    1. 1

                                                                                      PS1="[\W \A] "

                                                                                      Answers the two crucial questions: where and when?

                                                                                      1. 1
                                                                                        [username@host $CWD]$ 

                                                                                        And its coloured with named colours, so it really looks like this:

                                                                                        PS1="$HC$FWHT[$FBLE\u$FWHT@$FCYN\h $FYEL\W$FWHT]$ $RS"