2

I am customizing my bash prompt in order to make it look a little bit fancier. Here is what I did (in the ~/.bashrc file, Ubuntu 20.04).

# Customizing prompt
t1_bg="\[$(tput setab 31)\]"
t1_fg="\[$(tput setaf 31)\]"
t2_bg="\[$(tput setab 69)\]"
t2_fg="\[$(tput setaf 69)\]"
RESET="\[$(tput sgr0)\]"

triangle_1=$(echo -e "${t1_fg}${t2_bg}\uE0B0${RESET}")
triangle_2=$(echo -e "${t2_fg}\uE0B0")

PS1="${t1_bg} \u${RESET}${triangle_1}${t2_bg} \w ${RESET}${triangle_2}${RESET} "

enter image description here

As shown in the picture the triangles are a little off and the text is not centered vertically. Furthermore, I would a little bit more spacing between the prompt and the output. Is this any way to address these problems?

Finally, why the window title bar doesn't show the current directory? I modified only the PS1 variable.

3
  • 1
    You can add spaces at the end of the PS1 line if you want more spaces between the triangle and the starting cursor, but it would have to be complete spaces, not fractions thereof. The way the triangle looks is determined by the font, and what appears in the title bar depends on the terminal emulator you're using, neither of which you specified.
    – frabjous
    Jul 24, 2022 at 20:36
  • @frabjous I don't want lines between triangle and input but between triangle and output. The emulator is the default that is shipped with Ubuntu 20.04.
    – ado sar
    Jul 24, 2022 at 20:48
  • "Finally, why the window title bar doesn't show the current directory? I modified only the PS1 variable." – Your old (default) PS1 contained instructions to set the window title (OSC 0 escape sequence) upon printing the prompt, your new one apparently doesn't. Presumably the same goes for OSC 7 which makes the terminal open new tabs in the same directory. You should migrate / preserve these bits from your old PS1.
    – egmont
    Aug 22, 2022 at 0:46

1 Answer 1

0

As frabjous said in the comments the way the triangle looks depends on the font. I installed the hack-ttf fonts (as suggested by synth-shell) and the problem was fixed. Installation (at least on Ubuntu) can be done through:

sudo apt install fonts-hack-ttf

In order to fix the title bar I added on the end of .bashrc:

case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

I can't understand how this fixes the problem when the same code is also found earlier on bashrc. In general the final code that is added on the bashrc is:

# Customizing prompt
t1_bg="\[$(tput setab 31)\]"
t1_fg="\[$(tput setaf 31)\]"
t2_bg="\[$(tput setab 69)\]"
t2_fg="\[$(tput setaf 69)\]"
RESET="\[$(tput sgr0)\]"

triangle_1=$(echo -e "${t1_fg}${t2_bg}\uE0B0${RESET}")
triangle_2=$(echo -e "${t2_fg}\uE0B0")

case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    esac

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .