Urxvt prompt config location

Hi there,

So I’ve recently broke my Archlabs system, but that’s not what I’m here for, i’ll take care of that myself, one thing i am afraid of doing is losing my previous system files (only the configs, because they looked pretty) and one of the thing I enjoyed the most was the way that the terminal prompt was showing up, and I don’t remember if that came as default or not, but either way i would like to know which file is it located in and how can i customize it further.

It had like two lines, where the first showed the current path, then had an arrow in the line below where you would type your command. The thing i found most curious, is that a quick peak at my .bashrc file (by using an ext4 reader on windows) is:


# catch non-bash and non-interactive shells
[[ $- == *i* && $BASH_VERSION ]] && SHELL=/bin/bash || return 0

# set some defaults
export MANWIDTH=90
export HISTSIZE=10000
export HISTIGNORE="q:f:v"

# colors in less (manpager)
export LESS_TERMCAP_mb=$'\e[01;31m'
export LESS_TERMCAP_md=$'\e[01;31m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;44;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[01;32m'

# ensure ~/bin is on the path
[[ $PATH =~ ~/bin ]] || PATH=~/bin:$PATH

set -o vi
set -o notify

shopt -s direxpand
shopt -s checkhash
shopt -s sourcepath
shopt -s expand_aliases
shopt -s autocd cdspell
shopt -s extglob dotglob
shopt -s no_empty_cmd_completion
shopt -s autocd cdable_vars cdspell
shopt -s cmdhist histappend histreedit histverify
[[ $DISPLAY ]] && shopt -s checkwinsize

# prompt if file sourcing below fails
PS1='[\u@\h \W]\$ '

# uncomment these lines to disable the multi-line prompt
# add user@host, and remove the unicode line-wrap characters

# export PROMPT_LNBR1=''
# export PROMPT_USERFMT='\u\[\e[0m\]@\[\e[31m\]\h '
# source shell configs
for f in "$HOME/.bash/"*?.bash; do
    . "$f"

[ -f /opt/miniconda3/etc/profile.d/conda.sh ] && source /opt/miniconda3/etc/profile.d/conda.sh

Visiting the Arch wiki page tells me that the PS1 = “something” should be the way my prompt looked, but it isn’t. And looking at the comment above, it says “prompt if file sourcing below fails”, but i cannot locate the said file where I’m guessing the prompt is located.


Sorry about the comment turning into big bold letters, i don’t know how to turn that off.

Use triple backticks to create a code block: https://help.github.com/articles/creating-and-highlighting-code-blocks/

The prompt configuration depends on your shell, ArchLabs uses zsh as stock so it will be in ~/.zshrc (I think).

Check your shell with:

echo $SHELL


echo $0
1 Like

Have you looked in $HOME/.bash/ ?

Are you sure that your shell is bash? The prompt is a $ for bash or % for zsh.

yes im positive it is bash, however, my archlabs is 100% dead, i don’t know what’s wrong, i would just like to retrieve that prompt, and understand where it is located, and how to change it to suit my nerdy needs!

In $HOME/.bash/, there is a file named prompt.bash which might contain what I’m looking for, however, this is one big file and I don’t understand a single line of it, but so far I haven’t found any way to easily create or download your own bash prompt customization, so I’m unsure what to copy from here.

Yea the original prompt file uses a large (bloated) bit of git checking, I’ve done a rewrite and simplified it, as well as included a bit more configuration options.

I’m not going to go over it and explain, it’s a bash script so your best place to start understanding things is reading man bash (especially the PROMPTING section), however if you just want to tweak the prompt, try changing things (you’ll know when you’ve borked something).

The Arch wiki also has a great page on bash/prompt customization

If you read and understand both of those sources you’ll have no problem writing your own prompt.


# A fast, customizable, and informative bash prompt.
# Written by Nathaniel Maia, December 2018 - February 2019

# the main deal, prompt_main() builds PS1 each time bash calls PROMPT_COMMAND

# less commonly used prompts
PS2='==> '
PS3='choose: '

# bash uses \[..\] to wrap text in the prompt which we don't want to count as
# part of the prompt to avoid cursor position issues using completion and history
R='\[\e[0m\]'       BOLD='\[\e[1m\]'  RED='\[\e[31m\]'     GREEN='\[\e[32m\]'
YELLOW='\[\e[33m\]' BLUE='\[\e[34m\]' MAGENTA='\[\e[35m\]' CYAN='\[\e[36m\]'

{ # basic settings

    : "${PMT_PMT=\$}" # prompt symbol, a # when UID is 0, $ otherwise
    : "${PMT_USERFMT=""}" # user@host format string
    : "${PMT_NEWLINE=\n}" # newline char, set empty for single line prompt
    : "${PMT_SHCOL="$BLUE"}" # color for subshell name
    : "${PMT_WRAPCOL="$MAGENTA"}" # color for matching wrap characters

    if (( EUID == 0 )); then # we are root
        : "${PMT_USERCOL="$RED"}"
        # if not already defined, set USERFMT to the username when root
        PMT_USERFMT="${PMT_USERFMT:- \u}"
        : "${PMT_USERCOL="$CYAN"}"

    if [[ $PMT_NEWLINE ]]; then # prompt is multi line
        : "${PMT_LNBR1="┌"}"  # ┌ ┏ ╓ ╒
        : "${PMT_LNBR2="└"}"  # └ ┗ ╙ ╘
        : "${PMT_ARROW=">"}"  # ➜ ➤ ► ▻ ▸ ▹ ❯
        : "${PMT_LNBR1=">"}"

    # color the wraps

    # git settings
    : "${_GIT_PRE="("}"
    : "${_GIT_SEP="|"}"
    : "${_GIT_SUF=")"}"
    : "${_GIT_BRCH="${MAGENTA}"}"
    : "${_GIT_CNFL="${RED}x$R"}"
    : "${_GIT_CHGD="${BLUE}+$R"}"
    : "${_GIT_UNMG="${YELLOW}*$R"}"

    # these terminals (and likely more) don't support some of the characters
    # used for these git status variables, so we just use ASCII plain text
    if [[ $TERM =~ (linux|rxvt) ]]; then
        : "${_GIT_CLN="${GREEN}Ok$R"}"
        : "${_GIT_STGD="${RED}.$R"}"
        : "${_GIT_AHD="${GREEN}^$R"}"
        : "${_GIT_BHD="${RED}v$R"}"
        : "${_GIT_UNTR="${YELLOW}--$R"}"
        : "${_GIT_STSH="${BLUE}S$R"}"
        # these characters
        : "${_GIT_CLN="${GREEN}✔$R"}"
        : "${_GIT_STGD="${RED}•$R"}"
        : "${_GIT_AHD="${GREEN}↑$R"}" # ⇡
        : "${_GIT_BHD="${RED}↓$R"}"   # ⇣
        : "${_GIT_UNTR="${YELLOW}…$R"}"
        : "${_GIT_STSH="${BLUE}⚑$R"}"

{ # print the main prompt

    ecode=$? # last command exit code
    typeset ps1="" g="" # local string variables being added to

    # history commands to share across shells, see `history --help`
    history -n; history -w; history -c; history -r

    # set the terminal title for supporting terminals
    if [[ $TERM =~ (xterm|rxvt|st|alacritty|kitty) ]]; then
        ps1+="\[\033]0;${TERM/-256color/}: bash - \w\007\]"

    # beginning of 'actual' visible prompt

    # exit code was non-zero
    (( ecode != 0 )) && ps1+=" ${RED}$ecode${R}"

    # working directory

    # process parent
    cat /proc/$PPID/stat | while read l; do
        [[ $l != *'('*')'* ]] || { sl="${l#*\(}" sl="${sl%)*}"; }
    [[ $TERM == *"$sl"* || $SHELL == *"$sl"* ]] || ps1+=" ${PMT_SHCOL}($sl)"

    # git status
    [[ $PWD =~ (boot|bin|etc|usr|dev|lib|proc|sys|var) || $PWD == "$HOME" ]] || g="$(prompt_gitstats)"
    [[ $g ]] && ps1+=" $g"

    # multi line stuff

    # export what we have so far plus the finishing bits as PS1
    export PS1="$ps1 ${PMT_USERCOL}${PMT_PMT}${R} "

{ # print a string of git info (if any)
    git status --porcelain=v2 -b 2>/dev/null | (
        typeset c="$PWD" b='' d='' x='' y=''
        typeset -i H B G S C M A U # ints
        while read l; do case "$l" in
            'u'*) (( U++ )) ;;
            '?'*) (( A++ )) ;;
            *'.head'*) b="${l##*.head }" ;;
            *'.ab'*) l="${l#*.ab +}" H="${l% -*}" B="${l#* -}" ;;
            *[1-2]*) x="${l:2:1}" y="${l:3:1}"
                if [[ $x$y =~ (AA|AU|DD|DU|UA|UD|UU) ]]; then
                    (( C++ ))
                    [[ $x =~ [ACDMR] ]] && (( G++ ))
                    [[ $y =~ [CDMR]  ]] && (( M++ ))
                fi ;;
        esac done

        if [[ $b ]]; then
            while [[ $c && -z $d ]]; do
                [[ -d "$c/.git" ]] && d="$c/.git" || c="${c%/*}"
            if [[ -f $d/refs/stash ]]; then
                cat "$d/refs/stash" | while read l; do
                    (( S++ ))
            (( H )) && s+="$_GIT_AHD${H}";  (( B )) && s+="$_GIT_BHD${B}"; s+="$_GIT_SEP"
            (( G )) && s+="$_GIT_STGD${G}"; (( M )) && s+="$_GIT_CHGD${M}"
            (( C )) && s+="$_GIT_CNFL${C}"; (( U )) && s+="$_GIT_UNMG${U}"
            (( A )) && s+="$_GIT_UNTR${A}"; (( ! M && ! C && ! G && ! A && ! U )) && s+="$_GIT_CLN"
            (( S )) && s+="$_GIT_STSH${S}"
            printf "%s" "${s}${_GIT_SUF}${R}"

# enable the promptvars shell opt if not already
shopt -q promptvars || shopt promptvars >/dev/null 2>&1

# actually load the settings

# vim:ft=sh:fdm=marker:fmr={,}

To add it: copy it to a file somewhere and source it in your bashrc . /path/to/script, you can also just copy the script into your bashrc and do the changes at the top of the file (rather than before sourcing)

This prompt can be easily customized by setting a few variables in your bashrc before sourcing or before the actual prompt script.

Here’s an example for a more ‘standard’ prompt:


With the above settings

Without them

Can really turn it into any number of prompts just by setting a few variables accordingly. To understand what variables there are and what theyre for I suggest reading the prompt_defaults() function in that script above, most are commented with a short description but you can also just ask.