5 points · by simplecto · 1y ago · 5 comments
PS1 is the settings that give you the cool prompts on the command line.
I've gone searching for a directory of PS1's where I can browse, save, and try out different command prompts.
Do i need to make this? Or is my google-fu, perplexity-fu, and gpt-fu just not where it needs to be?
Or do I need to make one?
# Simple prompt
function set_bash_prompt {
status=$?
container=""
if test -f /run/.containerenv; then
container="($(cat /run/.containerenv | grep name | cut -d\" -f2)) "
fi
if test $status -eq 0 ; then
# Last command succeeded, set prompt to green
PS1="\[\e[0;32m\]"
else
# Last command failed, set prompt to red
PS1="\[\e[0;31m\]"
fi
PS1+="$container\w \$ \[\e[0m\]"
}
if [ -n "$SSH_CONNECTION" ]; then
export PS1="\u@\h: \w \$ "
else
# export PS1="\e[0;32m\]\w $ \[\e[0m\]"
PROMPT_COMMAND=set_bash_prompt
fi
export PROMPT_DIRTRIM=1 # number of trailing directory to retain when using \w
Note: I've used toolbox and distrobox, so the function at the top was just to add what current env I'm in. Kinda like venv.