Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a problem with command editing in bash. If all of the following are true...

  1. My (single-line) prompt is particularly long.
  2. The terminal window is relatively narrow.
  3. I pressed Ctrl+C to exit the previous process, so that ^C is displayed at the left of the line.
  4. The command I'm editing wraps to the next line.

...then the editing is messed up. I end up replacing characters offset by 2 positions from the ones I thought I was editing.

Similar things happen if, at step 4, I type in a command that spans multiple lines (rather than pressing Up). I can backspace onto the previous line, and then delete two characters of my prompt.

Basically this:

(Some output)
^Cuser@host:~/path/to/somewhere $ some long command
that wraps

Is broken by the ^C that appears at the start of the line.

I've tried some other commands (e.g. sleep 30), and the ^C appears on a line by itself, and the prompt appears on the next line. This only seems to happen with node.js: node some_command_that_wraps.js.

In case it's important, I have a brightly-coloured, git-integrated PROMPT_COMMAND. You can find it on github, in case I've done something stupid in that.

Update

My PS1 is (for example) set to (I've wrapped it slightly):

\[\e]0;\u@\h:\w\a\]
\[\e[0;93m\]\u@\h\[\e[0;96m\]:\w 
\[\e[0;97m\]{\[\e[0;94m\]master\[\e[0;92m\]\[\e[0;91m\] ~1\[\e[0;97m\]}
\[\e[0m\]\[\e[0;96m\]\$\[\e[0m\]

...which displays (with more colour):

roger@roger-p5q:~/Source/rlipscombe/bash_profile [master ~1] $ 

As far as I can tell, the escape characters are correctly non-countable (using \[ .. \]).

How do I either:

  • Get bash to detect the ^C and move to the next line?, or
  • Not mess up the command editing?
share|improve this question

migrated from superuser.com Sep 10 '13 at 17:43

This question came from our site for computer enthusiasts and power users.

    
Can you provide your bash version and the output of stty -a? –  Patrick Oct 13 '13 at 14:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.