 | These fixes have some drawbacks. First, they work only for the
specified terminals. Second, in theory (but this is unlikely to happen)
they could confuse the readline library on
other terminals. Both limitations are however mostly harmless. |
First of all, check with infocmp gnome
whether you already have a gnome entry in your
terminfo database (we will fix
termcap later). If the entry does not exist,
the following command
bash$ tic <(infocmp xterm |\
sed 's/xterm|/gnome|/' |\
sed 's/kbs=\\177,/kbs=^H,/' |\
sed 's/kdch1=\\E\[3~,/kdch1=\\177,/') |
will create a correct one in
~/.terminfo. If the same
command is launched by the root, it will generate the entry in the global
database (you can override this behaviour by setting
TERMINFO to
~/.terminfo). Note that if your
xterm
entry is already deviant (e.g., you have a Red Hat ≤5.0) the script will copy it unchanged, which is
exactly what we want.
Now, add the following snippet to
~/.inputrc[1]:
This line teaches the
readline library how to
manage your standard
Delete key for standard emulators,
and with a bit of luck it should not interfere with other
terminals. However, now we must also explain to the library the meaning
of the
DEL character on deviant terminals, for instance
by adding
$if term=gnome
DEL: delete-char
Meta-DEL: kill-word
"\M-\C-?": kill-word
$endif |
to
~/.inputrc. If
xterm
is deviant, too, you must add other three lines for it. On the other
hand, if no terminal emulator is deviant this part is not needed. All
these changes can be made global by altering the
/etc/inputrc file.
Note that the conditional assignments make deviant terminal
emulators work given that the TERM variable is
set correctly. To guarantee this, there are a number of
techniques. First of all, since the default value of the
TERM variable for
gnome-terminal is xterm, if
all terminals are not deviant then we do nothing. If, however, a terminal
that by default uses the xterm entry is deviant you
must find a way to set the TERM variable correctly; assume
for instance this is true of
gnome-terminal.
The simplest way to obtain this effect is to start
gnome-terminal with the argument
--termname=gnome, for instance by suitably setting the
command line in the launcher on the GNOME panel. If
however you have an old version, and this method does not work, you can
add the lines
if [ "$COLORTERM" = "gnome-terminal" ]
then
export TERM=gnome
fi |
to your
~/.bashrc configuration file
[2]. The assignment is executed
only under
gnome-terminal, and sets correctly the
TERM variable.
 | Setting the terminal to gnome could prevent
ls from using colours, as many versions of
ls do not know that
gnome-terminal is colour capable. To avoid this
problem, create a configuration file ~/.dircolors with
dircolors --print-database >~/.dircolors, and add a line
TERM=gnome to the configuration file. |
We will now generate on-the-fly a suitable
termcap entry for deviant terminal emulators; this
can be done as follows, always in ~/.bashrc:
if [ "$TERM" = "gnome" ]
then
export TERMCAP=$(infocmp -C gnome | grep -v '^#' | \
tr '\n\t' ' ' | sed 's/\\ //g' | sed s/::/:/g)
fi |
Finally, we must explain to the terminal device which character is
generated by the erase key. Since usually the erase key is expected to
backspace, there is a nice trick taken from the Red Hat
/etc/bashrc that works: add this to
~/.bashrc:
KBS=$(tput kbs)
if [ ${#KBS} -eq 1 ]; then stty erase $KBS; fi |
It's a simple idea: we read from the terminal database the capability
kbs, and set the erase character to its value if it is a
single character (which happens in both standard and deviant terminals).
 | Certain distributions could have fixes already in place in the
system-wide /etc/inputrc configuration file. In
this case you can eliminate redundant lines from your
~/.inputrc. |