2

When holding k or holding up, previously entered commands are shown, but at some point, the first 10 characters of a command longer than 10 characters stay. This is not always the first command longer than 10 characters encountered, but pressing ctrl+c and holding up again causes the same characters to stay.

$ echo test
test

$ echo thisisalongstring
thisisalongstring

# pressing `up` twice
$ echo thisiecho test # should be `echo test`
test
# even though `echo thisi` is shown, it is not executed 

Is there a way to fix this?

I didn't change anything in ~/.bashrc (except appending PS1='test ' for testing).

# this is the default ubuntu prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  • This happens both in gnome-terminal and konsole.
  • I tried appending PS1='test ' and PS1='' to ~/.bashrc, which contain no non-printable characters, but this still happens.
  • Executing PS1=$PS1 or PS1=$(echo $PS1) doesn't work.
  • Manually pasting the code above into the terminal solves this problem, but I have no idea why.
    • Echoing $PS1 after launching the terminal yields the same result as echoing $PS1 after manually pasting.
    • Executing . ~/.bashrc causes the prompt to revert to being bugged.

This question sounds similar to the already solved Why is my bash prompt getting bugged when I browse the history?, but this also happens when no non-printable characters are present in PS1.

4
  • What shell are you using? This doesn't happen on my system (alacritty).
    – Adam D.
    Sep 21, 2019 at 0:37
  • I tried it on gnome-terminal and konsole
    – Lukas T
    Sep 21, 2019 at 4:04
  • At a guess there is a missing close-escape sequence. Sep 21, 2019 at 13:22
  • But it still happens if PS1 is an empty string
    – Lukas T
    Sep 21, 2019 at 13:35

1 Answer 1

0

This works without changing PS1:

custom_prompt(){
    # default ubuntu prompt
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
}

PROMPT_COMMAND=custom_prompt

You must log in to answer this question.

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