You are not logged in.

#1 2020-12-07 05:06:06

polgesteirg
Member
Registered: 2020-12-07
Posts: 6

Terminal characters overlapping into prompt and other strange behavior

Yesterday I edited my prompt and everything was working fine. After booting up today though I can barely type commands after about 20 characters since they'll overlap into my prompt (in the same line) and if I press backlash when overlapped they make the prompt disappear.

I have proper monospace fonts installed and have checked for unscaped characters in my .bashrc prompt, but I can't see any. I'm quite new to bash in general though so it's possible that unscaped characters might be the problem.

My .bashrc:

 
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

system_info(){
        uname -r
}

light_Orange="tput setaf 216"
dark_Blue="tput setaf 33"
light_Green="tput setaf 76"
reset="tput sgr0"

PS1='`$light_Orange` ($('system_info')) `$dark_Blue`\u:`$light_Green`/\W`${reset}`$'

alias ls='ls --color=auto'
shopt -s autocd         #no need to type cd bruh

alias grep='grep --color=auto'
alias ..='cd ..'
alias mv='mv -i'

export PATH
export HISTCONTROL=ignoreboth
export EDITOR=nano
export BROWSER=firefox-developer

unclutter &

Any help would be appreciated!

Edit: I don't know if it matters but I'm using KDE plasma for my DE and Terminator for my terminal.

Last edited by polgesteirg (2020-12-07 05:11:39)

Offline

#2 2020-12-07 08:17:08

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: Terminal characters overlapping into prompt and other strange behavior

You need to put "\[" and "\]" around your color codes. Bash needs those "\[ \]" to count how far the cursor moves.

I'd recommend to put the "\[ \]" directly into your color variables:

light_Orange="\[$(tput setaf 216)\]"
...

PS1='$light_Orange ...'

In this example I also removed the "`" backticks you were using. I instead put "$(...)" into the variable.

Offline

#3 2020-12-07 12:30:31

polgesteirg
Member
Registered: 2020-12-07
Posts: 6

Re: Terminal characters overlapping into prompt and other strange behavior

Ropid wrote:

You need to put "\[" and "\]" around your color codes. Bash needs those "\[ \]" to count how far the cursor moves.

I'd recommend to put the "\[ \]" directly into your color variables:

light_Orange="\[$(tput setaf 216)\]"
...

PS1='$light_Orange ...'

In this example I also removed the "`" backticks you were using. I instead put "$(...)" into the variable.

Thank you very much! I did read about the bash characters, but somehow managed to forget everything about them.

I also switched to using double quotes ("") since it makes everything easier. This made that much clearer:
https://stackoverflow.com/questions/669 … es-in-bash

Here's the updated bash if anyone's interested:

system_info(){
        uname -r
}

light_Orange="\[$(tput setaf 216)\]"
dark_Blue="\[$(tput setaf 33)\]"
light_Green="\$(tput setaf 76)\]"
reset="\[(tput sgr0)\]"

PS1="${light_Orange} ($(system_info)) ${dark_Blue}\u: ${light_Green}/\W${reset}"

Offline

#4 2020-12-07 13:56:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,515
Website

Re: Terminal characters overlapping into prompt and other strange behavior

You still have a typo (missing the opening square bracket) in light_Green.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB