Command line editing issue

Hi guys.
In terminal, using /bin/sh, when I search for some command in history (Ctrl+R) I get for example following command:

# diff -Naur dir.orig dir > some.patch
bck:diff


When I press Enter, it works fine, but If I want to edit the command and press for example 'RightArrow' button, I get [C added to command line:

# [Cdiff -Naur dir.orig dir > some.patch

If I press 'LeftArrow' button i get

# [Ddiff -Naur dir.orig dir > some.patch

which is quite inconvenient, since I always have to remove these escape sequences. I've been trying to figure out how to fix this, but to no avail. Does anyone know how to fix the situation?
 
The manual for sh(1) tells me that, by default, it has command history editing compatible with vi(1), so it's bi-modal, and enters history editing mode when the Esc key (a.k.a. "^[") is pressed. The editing commands you then use are the same as you would with vi.

If you are seeing unexpected characters with certain keystrokes, then you should check your terminal emulation is correct. You need to set the environment variable TERM correctly for the terminal emulation you are using.

For example, my X11 terminal emulator session sets TERM automatically when I login with export TERM=xterm-256color. YMMV greatly, depending on the terminal client you use and how you login.
 
I use emacs editing mode:

# cat .shrc
#
# .shrc - bourne shell startup file
#
set -o emacs

The effect is repeated on the FreeBSD console, where TERM=xterm, and when connecting via ssh, TERM=st-256color. I set TERM=xterm, but nothing changed.
 
Setting to "xterm-256color" doesn't help. I think that's not the case because I haven't modified anything in termcap. The changes that I made:

# cat .editrc
history size 2096
history unique 1


# cat .profile
...
export TERM=${TERM:-xterm}
export ENV=/root/.shrc




# cat .shrc
...
set -o emacs

bind ^[[A ed-search-prev-history
bind ^[[B ed-search-next-history
bind ^[[5C em-next-word
bind ^[[5D ed-prev-word



# cat /etc/rc.conf
...
keyrate="250.46"
keymap="ru"
 
Given that left arrow generates three octets <ESC>, '[', and 'D', and right arrow generates the three octets <ESC>, '[', and 'C', would you please explain what you intend with those key bindings?
 
Given that left arrow generates three octets <ESC>, '[', and 'D', and right arrow generates the three octets <ESC>, '[', and 'C', would you please explain what you intend with those key bindings?
I didn't actually set these shortcuts ([C, [D, etc.) on purpose. I believe they are set by default.
 
I've notived that default FreeBSD installation ISO image has this same issue:
 

Attachments

  • 2.png
    2.png
    139.4 KB · Views: 63
Back
Top