Show your PS1 (the bash prompt gallery)


#1

Lets see if a PS1 thread might be as successful as the Show your Desktop threads.

I’ll start with mine - it’s not that flashy but it helps me lots to keep a good overview of where I am and further more “whoami”!


PS1='\[$(tput bold)\]\u\[$(tput sgr0)\]@\h:\[$(tput sgr0)\]\[\033[38;5;33m\][\[$(tput sgr0)\]\[\033[38;5;39m\]\w\[$(tput sgr0)\]\[\033[38;5;33m\]]\[$(tput sgr0)\]\[\033[38;5;15m\]\\$ \[$(tput sgr0)\]'


PS1='\[$(tput bold)\]\[\033[38;5;1m\]\u\[$(tput sgr0)\]\[$(tput sgr0)\]\[\033[38;5;11m\]@\h:\[$(tput sgr0)\]\[\033[38;5;33m\][\[$(tput sgr0)\]\[\033[38;5;39m\]\w\[$(tput sgr0)\]\[\033[38;5;33m\]]\[$(tput sgr0)\]\[\033[38;5;15m\]\\$ \[$(tput sgr0)\]'


How to change init terminal colors
[SOLVED] Changing color in terminal
Urxvt color problem
#2

PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs

__prompt_command() {
    local EXIT="$?"             # This needs to be first
    PS1=""

    local RCol='\[\e[0m\]' 	# Right color

    local Red='\[\e[0;31m\]'
    local Gre='\[\e[0;32m\]'
    local BYel='\[\e[1;33m\]'
    local BBlu='\[\e[1;34m\]'
    local Pur='\[\e[0;35m\]'
    
    # Prompt prefix
    PS1="${BBlu}\w${BYel}$(parse_git_branch)${RCol} "

    if [ $EXIT != 0 ]; then
        PS1+="${Red}${EXIT}${RCol} $ ${RCol}"      # Add red if exit code non 0
    else
        PS1+="$ ${RCol}"
    fi
}

#git branch display
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | sed -e 's/master/M/g'
}

#3

i install a “big” font
aur:nerd-fonts-hack
configure my terminal (tilix) with this font

Add one function in ~/.bashrc

last_char()
    {
        declare MANJARO='\uf312'      # logo manjaro par defaut
        [[ "$(pwd)" =~ "/workspace" ]] && MANJARO='\ue70c'      
        [[ "$(pwd)" =~ "/www" ]] && MANJARO='\uf81e'
        [[ "$(pwd)" =~ "/C++" ]] && MANJARO='\ufb71'
        [[ "$(pwd)" =~ "/bash" ]] && MANJARO='\uf489'
        [[ "$(pwd)" =~ "/etc" ]] && MANJARO='\uf425'
        [[ "$(pwd)" == "/home/$(whoami)" ]] && MANJARO='\uf46d'
        [[ "$(pwd)" =~ "/Images" ]] && MANJARO='\ue60d'
        echo -en "\n${MANJARO}"
    }

small change original second PS1 : \$ by \$(last_char)

export PS1="\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$(last_char)\[\033[00m\] "

result (manjaro by default):

and:


#4

When I get bored I love playing with stuff like this. So, I redid my PS1 today. I must say I like the result of my fiddling around.

	if [[ ${EUID} == 0 ]] ; then
		PS1='\[\033[01;31m\] \u@\h\[\033[0;33m\] \w\[\033[01;31m\]] \[\033[00m\] \n\$ '
	else
		PS1='\[\033[01;32m\] \u@\h\[\033[01;34m\] \w\[\033[38;5;33m\] \[\033[38;5;33m\]\n\$ '
	fi


#5

I’d really would not like this thread to die - arn’t you folks cusomizing your bash/zsh/… prompts?


#6

I was kind of surprised at the lack of response as well. I thought more people would like to share their prompts. Kind of a shame because I’m sure there’s some great examples out there.


#7

ok, a new
with bash functions , we can add all infos

  • Number of files in curent directory

in .bashrc

prompt_get_nb_files() {
    nb=$(ls -AGU --width=1 | wc -l)
    ((nb>0)) && echo -n " ($nb)"
}

in PS1, only call function \$(prompt_get_nb_files)

result (55 files in my directory):

cd ~/.local/bin/
[patrick@MyMachine ~/.local/bin] (55)

  • or memory used :
prompt_mem() {
    echo -n " ($(free -h | awk '/^Mem/ {print $3"/"$2}'))"
}

[patrick@MyMachine ~] (194) (1,3Gi/5,7Gi)


#8

Here is mine :upside_down_face:

prompt

PS1=’[\033[01;32m]|[\033[01;37m]\t[\033[01;32m]| [\033[01;37m]\u[\033[01;32m]:[\033[01;37m]\h [\033[01;32m]|[\033[01;33m]\w[\033[01;32m]| $[\033[00m] ’
(sorry, I don’t know how to make it shorter…)


#9

I also have a pretty long string in the PS1 variable but I added a Return almost at the end, just before the $ sign, which will then be placed on the next line. This to start commands from the left side of the terminal instead of somewhere in the middle.


#10

Yes, I do the same thing. I prefer the entire path be shown and I have a lot of nested folders, so want my prompt to start on the next line as well.


#11

zsh for me:

image


#12

It looks nice @xircon, but how about including the code for generating your PS1.


#13

grafik

Do not ask for code, can not remember, I am old :disappointed_relieved:

Who am I??? :wink:

Maybe ;-)
# Change the window title of X terminals
case ${TERM} in
	xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
		PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
		;;
	screen*)
		PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
		;;
esac

use_color=true

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs}    ]] \
	&& type -P dircolors >/dev/null \
	&& match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true

if ${use_color} ; then
	# Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
	if type -P dircolors >/dev/null ; then
		if [[ -f ~/.dir_colors ]] ; then
			eval $(dircolors -b ~/.dir_colors)
		elif [[ -f /etc/DIR_COLORS ]] ; then
			eval $(dircolors -b /etc/DIR_COLORS)
		fi
	fi

	if [[ ${EUID} == 0 ]] ; then
		PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
	else
		PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] '
	fi

	alias ls='ls --color=auto'
	alias grep='grep --colour=auto'
	alias egrep='egrep --colour=auto'
	alias fgrep='fgrep --colour=auto'
else
	if [[ ${EUID} == 0 ]] ; then
		# show root@ when we don't have colors
		PS1='\u@\h \W \$ '
	else
		PS1='\u@\h \w \$ '
	fi
fi

#14

The code for that should (normaly) be in .bashrc file located in the users home direcotry under PS1="…" =)


#15

Oops - it is spaceship with some colour changes :smiley:


#16

This caught my eye so I decided to try your little setup.
Glad I took the time. :+1:
Thanks


#17

git users, for a few days we have gitprompt-rs in repos