Weird behavior in Xfce4-terminal and Bash

Hello!

Anyone have ever seen and solved this problem?

I typed as example a lot of “s”. Then i type arrow up to look for the previous command in the history. But however some “ssssssssssssssss” stay and the last command “clear” appear after it.

Any help is appreciated. Thank you :bowing_man:

This is probably just an artifact of the way the different color codes were implemented in the shell prompt.

Many people learn how to implement fancy colors in their prompt by way of so-called escape codes, but they also have to be properly terminated, because escape codes are not only used for changing colors, but also for cursor placement and overwriting screen locations that had previously been written to. It’s actually not just the shell that’s responsible for this, but also the terminal. It’s an interaction between the two.

There is ample documentation on the web regarding prompt customization, and some of that goes very deep. You can look into that, if you will. Here are a couple of links to get you started. :wink:


Addendum

I myself am using a function in my ~/.bashrc which allows me to have a customized prompt and change the color at will… :arrow_down:

cprompt () {

  if [ ! -z $1 ]
  then
    case $1 in

      "green"  )
         clrprompt="\[\e[1;32m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      "yellow" )
         clrprompt="\[\e[1;33m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      "blue"   )
         clrprompt="\[\e[1;34m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      "pink"   )
         clrprompt="\[\e[1;35m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      "cyan"   )
         clrprompt="\[\e[1;36m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      "white"  )
         clrprompt="\[\e[1;37m\]\n[\h:\$(/usr/bin/tty)][\${PWD}]\n[\t][\u] \[\e[1;37m\]>\[\e[0m\] "
         ;;
      *        )
         echo
         echo "     The only options available are: "
         echo
         echo "         green | yellow | blue | pink | cyan | white"
         echo
         return
         ;;
    esac
    PS1=${clrprompt}
  else
         echo
         echo "     No color specified."
         echo
         return
  fi
} 

export -f cprompt
cprompt yellow

It makes my prompt look like this ─ I’ve chosen yellow as the default… :arrow_down:


[nx-74205:/dev/pts/1][/home/aragorn]
[20:00:00][aragorn] > 

2 Likes

Thank you @Aragorn ! I know these documentations but didn’t read everything.

Solved it by using colors like this green="\033[0;32m" \[$green\], it was like this before $green, since you mentioned escaping colors. :grin:

I learned something :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.