Colourful prompt

28 views
Skip to first unread message

Qubes

unread,
May 3, 2023, 10:06:51 AM5/3/23
to qubes...@googlegroups.com
I have noticed on Fedora, the cli prompt itself is not colourful
although the rest of the output is. Is there a way to get the prompt
itself in colour as well? The prompt on Debian is in colour, it makes it
easier to find things when the prompt is in colour aswell.

Andrew David Wong

unread,
May 4, 2023, 8:01:56 AM5/4/23
to Qubes, qubes...@googlegroups.com
On 5/3/23 4:02 AM, Qubes wrote:
> I have noticed on Fedora, the cli prompt itself is not colourful although the rest of the output is. Is there a way to get the prompt itself in colour as well? The prompt on Debian is in colour, it makes it easier to find things when the prompt is in colour aswell.
>

Since this is not a Qubes-specific question, you might have better luck searching the web for how to do this in Fedora (or Linux in general) or asking in a Fedora (or general Linux) venue.

unman

unread,
May 4, 2023, 8:07:49 AM5/4/23
to Andrew David Wong, Qubes, qubes...@googlegroups.com
I wonder if this *is* Qubes specific, as it is stated that the Debian
prompt is in color. (Implicit, I think, is the suggestion that the color
matches the window decorations.)
OP - is that what you see? That the prompt is consistent with the window
decoration set by Qubes?

Qubes

unread,
May 4, 2023, 9:10:01 AM5/4/23
to qubes...@googlegroups.com
No the colour of the prompt does not follow the window decoration, I was
wondering if this isn't maybe a problem only on Fedora on Qubes and not
Fedora in general. I don't have a Fedora standalone I can check on. I
just found it odd that the prompt on Debian would be in colour (Green,
and it is real easy to find in between a lot of other output) and on
Fedora it is the same colour as the text you type. But as I was
re-reading my reply here I just had another look over and I just
discovered that the prompt on some of the Fedora VMs is in colour, also
a bright green, and some of them are default text colour. So in essense
it doesn't have anything to do with Qubes. I am a little confused though
because I can swear some of the VMs that I previously check where the
prompt was the default text colour now has a colourful prompt. (head
scratch head scratch)

I do see this in .bashrc on Debian and there is nothing of it in .bashrc
on Fedora. There is in fact a lot of stuff in .bashrc on Debian that is
not there on Fedora.

.bashrc

===truncated===

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

===truncated===

I have copied it over to .bashrc on Fedora and uncommented
`force_color_prompt=yes` but it makes no difference.

Qubes

unread,
May 4, 2023, 9:16:31 AM5/4/23
to qubes...@googlegroups.com
It must be because of a dependency that gets installed along the way
because booting the vanilla Fedora-37 template it does not have a
colourful prompt. I don't install anything specific for this myself.
Glad we cleared that up :-)

NewRoot

unread,
May 6, 2023, 6:33:48 AM5/6/23
to qubes-users
> I do see this in .bashrc on Debian and there is nothing of it in .bashrc
> on Fedora. There is in fact a lot of stuff in .bashrc on Debian that is
> not there on Fedora.

I use a custom color prompt for my bash shell.  I had to use different methods in my Fedora and Debian qubes to get the prompt I wanted.  It's a little tricky because you have to check and see how the system files setup the $PS1 file.  Because I wanted the same definition in each of my qubes I ended up creating a /etc/profile.d/custom.sh file to define the prompt in Fedora templates to set the prompt in each appVM based on that template.  The code  based on some adapted Debian or Ubuntu code.  There is also a bunch of code to setup definitions for colors and other terminal escape sequences.

My custom.sh produces prompt like:

[user@docker-fed-37:2 Fri 2023-05-05 17:35 GMT /etc/profile.d]$

where
user@docker-fed-37 is green
/etc/profile.d is bright_blue
the :2 represents the terminal number where numbering starts with :0


===custom.sh===

# User specific aliases and functions

term-control-colors () {
# https://mywiki.wooledge.org/BashFAQ/037
# Variables for terminal requests.
[[ -t 2 ]] && {
    alt=$(      tput smcup  || tput ti      ) # Start alt display
    ealt=$(     tput rmcup  || tput te      ) # End   alt display
    hide=$(     tput civis  || tput vi      ) # Hide cursor
    show=$(     tput cnorm  || tput ve      ) # Show cursor
    save=$(     tput sc                     ) # Save cursor
    load=$(     tput rc                     ) # Load cursor
    bold=$(     tput bold   || tput md      ) # Start bold
    stout=$(    tput smso   || tput so      ) # Start stand-out
    estout=$(   tput rmso   || tput se      ) # End stand-out
    under=$(    tput smul   || tput us      ) # Start underline
    eunder=$(   tput rmul   || tput ue      ) # End   underline
    reset=$(    tput sgr0   || tput me      ) # Reset cursor
    blink=$(    tput blink  || tput mb      ) # Start blinking
    italic=$(   tput sitm   || tput ZH      ) # Start italic
    eitalic=$(  tput ritm   || tput ZR      ) # End   italic
[[ $TERM != *-m ]] && {
    red=$(      tput setaf 1|| tput AF 1    )
    green=$(    tput setaf 2|| tput AF 2    )
    yellow=$(   tput setaf 3|| tput AF 3    )
    blue=$(     tput setaf 4|| tput AF 4    )
    bright_blue=$(     tput setaf 12|| tput AF 12    )
    magenta=$(  tput setaf 5|| tput AF 5    )
    cyan=$(     tput setaf 6|| tput AF 6    )
# for broken termcap databases with 16 ANSI colors
# blue=$'\e[0;34m'
# green=$'\e[0;32m'
# white=$'\e[0;37m'

}
    white=$(    tput setaf 7|| tput AF 7    )
    default=$(  tput op                     )
    eed=$(      tput ed     || tput cd      )   # Erase to end of display
    eel=$(      tput el     || tput ce      )   # Erase to end of line
    ebl=$(      tput el1    || tput cb      )   # Erase to beginning of line
    ewl=$eel$ebl                                # Erase whole line
    draw=$(     tput -S <<< '   enacs
                                smacs
                                acsc
                                rmacs' || { \
                tput eA; tput as;
                tput ac; tput ae;         } )   # Drawing characters
    back=$'\b'
} 2>/dev/null ||:
}

# set local definitions
term-control-colors

# my_blue=$'\e[0;34m'
# my_green=$'\e[0;32m'
# my_white=$'\e[0;37m'
# my_reset=$'\e[00m'


# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes


if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
    else
color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='[\[$green\]\u@\h\[$reset\]:\l \D{%a %F %R %Z} \[$bright_blue\]\w\[$reset\]]\$ '
    # PS1='[\[\033[01;32m\]\u@\h\[\033[00m\]:\l \D{%a %F %R %Z} \[\033[01;34m\]\w\[\033[00m\]]\$ '
else
    PS1='[\u@\h:\l \D{%a %F %R %Z} \w]\$ '
fi
unset color_prompt force_color_prompt

===custom.sh===


Another alternative I explored is the setup the above or similar file in the appVM .bashrc.d file.

Unfortunately, the Debian default overrides any $PS1 string defined /etc/profile.d/custom.sh so I define and export a $CUSTOM_PS1 environment variable and then use it appropriately in my Debian .bashrc to set the $PS1 string.  Also note that the term-control-colors function doesn't work in Debian login shell and the "my_" variable definitions can be used instead.


 
Reply all
Reply to author
Forward
0 new messages