DEV Community

John Mercier
John Mercier

Posted on

What is your $PS1?

Everyone has a different preference for $PS1 in bash what is yours?

Top comments (11)

Collapse
 
fennecdjay profile image
Jérémie Astor
%b%k%s%u%F{%(?.076.196)}${${P9K_CONTENT::="❯"}+}${:-"❯"}%b%k%f%s%u 

But it's automagically set in my .zhsrc.

at the top

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; t>
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

and later on

[ -z "$DISPLAY" ] || source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-th>
Collapse
 
moaxcp profile image
John Mercier

That is nice! I never thought of displaying the powerlevel in PS1. I should try out zsh or maybe fish as well.

Collapse
 
benaryorg profile image
#benaryorg

The reason I switched to zsh a few years back is that zsh's vi-mode can do visual whereas bash couldn't (can't?).
Cut&paste within your command line can be super handy, like when you, once again, forgot that git does parameters BSD style so no options after the argument, and you have to move either arguments or options.

Collapse
 
moaxcp profile image
John Mercier

I have this in my nixos configuration

        set_prompt () {
          if [[ "$?" == 0 ]]; then
            PS1=""
          else
            PS1="\[\e[01;31m\]($?) "
          fi
          PS1+="\[\e[01;;34m\]\\\$\[\e[00m\] "
        }
        export PROMPT_COMMAND="set_prompt; history -a; history -c; history -r;"

It is very minimal. Either a $ or (1) $. I use screen and I have common directories already open using .screenrc. This helps me avoid jumping between directories a lot. I also don't really need to know what user or machine I am on. If I get confused there is a command to look it up.

Collapse
 
benaryorg profile image
#benaryorg

And there I thought I was going for the bare minimum xD
I admire your workflow though, it seems pretty strict and probably comes with quite some efficiency.

Collapse
 
moaxcp profile image
John Mercier

It works for me. It may not be as useful for some users that want more info. I'm tempted to add the git branch but I'm not sure that I need it. I mostly use my IDE for git anyway except when I work on nixos.

Collapse
 
benaryorg profile image
#benaryorg

My zsh is configured to be minimal, no fancy characters, no fancy features for git, just a plain prompt in the Gentoo style.
The only difference is the last character ($ in bash, % in zsh) which is either green or red depending on the last exit code.
I need to rely on the prompt, on its position and looks, so nothing with variable length except for the path (which only the shell itself can change).
Beyond the prompt however starts syntax highlighting for my command and everything, so it is really just the prompt that I want to be static as an anchor of sorts.

PROMPT="%B%(!.%F{red}.%F{green}%n@)%m%k %B%F{blue}%(!.%1~.%~) %F{%(?.green.red)}%# %b%f%k"

Code over on GitHub.

Collapse
 
ianturton profile image
Ian Turton

${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}

Which generates something like this in a git enabled directory:

Collapse
 
snikhill profile image
Nikkhiel Seath

A Unicorn Symbol, My Name, Current Directory, Current Git Branch.

Nothing Fancy :)

Collapse
 
dimpiax profile image
Dmytro Pylypenko

I've found the cool generator: bashrcgenerator.com

Collapse
 
moaxcp profile image
John Mercier

Very cool!