Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 965e33040dd61030a94f0eb89877aee8 > files > 570

howto-html-en-20080722-2mdv2010.1.noarch.rpm

<HTML
><HEAD
><TITLE
>What You Should Do On Your System</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Linux Backspace/Delete mini-HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="What You Should Do When Writing Applications"
HREF="writing.html"><LINK
REL="NEXT"
TITLE="What If Nothing Works"
HREF="notwork.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux <B
CLASS="KEYCAP"
>Backspace</B
>/<B
CLASS="KEYCAP"
>Delete</B
> mini-HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="writing.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="notwork.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="SYSTEM">6. What You Should Do On Your System</H1
><P
>Note again that the main issue that confuses people trying to fix
	 their system is that usually they are fixing thing in the wrong
	 place. Since the parts that work often just work by chance, trying to fix
	 the system assuming something is broken will often lead to change correct
	 settings into incorrect settings.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN209">6.1. What Needs to Be Done</H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="DEVIANCE">6.1.1. Detecting Deviance</H3
><P
>The first step towards a clean solution is to know exactly which
		  terminals are deviant and which not. Usually they all behave like the
		  console, and in this case the modifications to get everything working
		  are minimal. If, however, you have some deviant terminal (e.g., a
		  deviant version of <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
>), you will
		  have to treat it in a special way.</P
><P
>The following C one-liner
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;void main(void) {int c; while(c = getchar()) printf("%d 0x%02X\n", c, c);}</PRE
></FONT
></TD
></TR
></TABLE
>
may help you. Put the line into a file named <TT
CLASS="FILENAME"
>ascii.c</TT
>,
compile it with <B
CLASS="COMMAND"
>gcc ascii.c -o ascii</B
>, type
<B
CLASS="COMMAND"
>./ascii</B
> and press a key followed by <B
CLASS="KEYCAP"
>RETURN</B
>.
The program will display the decimal and hexadecimal codes of the
<SPAN
CLASS="ACRONYM"
>ASCII</SPAN
> sequence produced (you may want to do a <B
CLASS="COMMAND"
>stty
erase ^-</B
> first to get really all the codes). Now you can easily see
what <B
CLASS="KEYCAP"
>Backspace</B
> key does: if it emits a <SPAN
CLASS="SYMBOL"
>DEL</SPAN
>
(127), you have a standard emulator, if it emits a <SPAN
CLASS="SYMBOL"
>BS</SPAN
> (8) you have
a deviant one.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN226">6.1.2. Distinguishing Between Emulators</H3
><P
>If you have some deviant terminal emulator, you must distinguish
		  it from the standard ones.  Theoretically, this should not be a problem
		  because there are different entries in the terminal database for
		  terminals with different sequences (the entry used depends on the value
		  of the <TT
CLASS="ENVAR"
>TERM</TT
> variable).</P
><P
>Here we take the approach that the <TT
CLASS="LITERAL"
>gnome</TT
> entry
        should be used for all deviant VT100 emulators, and the
        <TT
CLASS="LITERAL"
>xterm</TT
> entry for the standard ones. This is in line
        with several distributions (except a few cases like RedHat &#8804;5.0,
        where the <TT
CLASS="LITERAL"
>xterm</TT
> entry is deviant).</P
><P
>However, <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> uses by
        default the same entry as <SPAN
CLASS="APPLICATION"
>xterm</SPAN
>, so if one
        is deviant and the other one is not you will need to find a way to tell
        them apart. The option <TT
CLASS="LITERAL"
>termname</TT
> of
        <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> allows the user to set the
        <TT
CLASS="ENVAR"
>TERM</TT
> variable to a more sensible name. However, in older
        versions of <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> the option does
        not work. Moreover, sometimes it is not easy to modify the way
        <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> is started.</P
><P
>A good idea here is to exploit the fact that
		  <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> sets the
		  <TT
CLASS="ENVAR"
>COLORTERM</TT
> variable to
		  <TT
CLASS="LITERAL"
>gnome-terminal</TT
>. Thus, by adding a simple test to the
		  shell configuration files we can fix the <TT
CLASS="ENVAR"
>TERM</TT
>
		  variable.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN247">6.1.3. Fixing the Terminal Database</H3
><P
>Our problem now is that the terminal database could lack a
		  <TT
CLASS="LITERAL"
>gnome</TT
> entry for deviant terminals (this happens on a
		  number of <SPAN
CLASS="APPLICATION"
>termcap</SPAN
> and
		  <SPAN
CLASS="APPLICATION"
>terminfo</SPAN
> versions). Recent
		  <SPAN
CLASS="APPLICATION"
>terminfo</SPAN
> databases have an entry
		  <TT
CLASS="LITERAL"
>gnome</TT
>, but, in any case, since
		  <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> behaves essentially like
		  <SPAN
CLASS="APPLICATION"
>xterm</SPAN
> modulo our famous two keys, it is
		  possible to automagically generate a brand new correct entry.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN257">6.1.4. Fixing the Shell Behaviour</H3
><P
>The <SPAN
CLASS="APPLICATION"
>readline</SPAN
> library used by the
		  <SPAN
CLASS="APPLICATION"
>bash</SPAN
> and by many other programs to read the
		  input line can be customized so to recognize specific sequences of
		  characters. The customization can also depend on the
		  <TT
CLASS="ENVAR"
>TERM</TT
> variable, so once we can distinguish terminals we
		  can do fine tuning of the keyboard.</P
><P
>Moreover, if you want <SPAN
CLASS="APPLICATION"
>less</SPAN
> and other
		  application that do raw line input to work correctly, you must convince
		  the shell that under a deviant terminal emulator the erase character is
		  <SPAN
CLASS="SYMBOL"
>BS</SPAN
>, and not <SPAN
CLASS="SYMBOL"
>DEL</SPAN
> (in the other case
		  the <B
CLASS="KEYCAP"
>Backspace</B
> key is already emitting
		  <SPAN
CLASS="SYMBOL"
>DEL</SPAN
>, so we do not have to do anything). This can be
		  done using the command <B
CLASS="COMMAND"
>stty</B
>.</P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN270">6.2. How to Do It</H2
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>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 <SPAN
CLASS="APPLICATION"
>readline</SPAN
> library on
		  other terminals. Both limitations are however mostly harmless.</P
></TD
></TR
></TABLE
></DIV
><P
>First of all, check with <B
CLASS="COMMAND"
>infocmp gnome</B
>
		whether you already have a <TT
CLASS="LITERAL"
>gnome</TT
> entry in your
		<SPAN
CLASS="APPLICATION"
>terminfo</SPAN
> database (we will fix
		<SPAN
CLASS="APPLICATION"
>termcap</SPAN
> later). If the entry does not exist,
		the following command

<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;bash$ tic &#60;(infocmp xterm |\
        sed 's/xterm|/gnome|/' |\
        sed 's/kbs=\\177,/kbs=^H,/' |\
        sed 's/kdch1=\\E\[3~,/kdch1=\\177,/')</PRE
></FONT
></TD
></TR
></TABLE
>

will create a correct one in <TT
CLASS="FILENAME"
>~/.terminfo</TT
>. 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 <TT
CLASS="ENVAR"
>TERMINFO</TT
> to
<TT
CLASS="FILENAME"
>~/.terminfo</TT
>). Note that if your <TT
CLASS="LITERAL"
>xterm</TT
>
entry is already deviant (e.g., you have a Red Hat &#8804;5.0) the script will copy it unchanged, which is
exactly what we want.</P
><P
>Now, add the following snippet to
		<TT
CLASS="FILENAME"
>~/.inputrc</TT
><A
NAME="ADDINPUTRC"
HREF="#FTN.ADDINPUTRC"
>[1]</A
>:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;"\e[3~": delete-char</PRE
></FONT
></TD
></TR
></TABLE
>
      This line teaches the <SPAN
CLASS="APPLICATION"
>readline</SPAN
> library how to
      manage your standard <B
CLASS="KEYCAP"
>Delete</B
> 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 <SPAN
CLASS="SYMBOL"
>DEL</SPAN
> character on deviant terminals, for instance
      by adding
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;$if term=gnome
DEL: delete-char
Meta-DEL: kill-word
"\M-\C-?": kill-word
$endif</PRE
></FONT
></TD
></TR
></TABLE
>
      to <TT
CLASS="FILENAME"
>~/.inputrc</TT
>. If <SPAN
CLASS="APPLICATION"
>xterm</SPAN
>
      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
      <TT
CLASS="FILENAME"
>/etc/inputrc</TT
> file.</P
><P
>Note that the conditional assignments make deviant terminal
		emulators work <EM
>given that the <TT
CLASS="ENVAR"
>TERM</TT
> variable is
		set correctly</EM
>. To guarantee this, there are a number of
		techniques.  First of all, since the default value of the
		<TT
CLASS="ENVAR"
>TERM</TT
> variable for
		<SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> is <TT
CLASS="LITERAL"
>xterm</TT
>, if
		all terminals are not deviant then we do nothing. If, however, a terminal
		that by default uses the <TT
CLASS="LITERAL"
>xterm</TT
> entry is deviant you
		must find a way to set the <TT
CLASS="ENVAR"
>TERM</TT
> variable correctly; assume
		for instance this is true of
		<SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
>.</P
><P
>The simplest way to obtain this effect is to start
      <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> with the argument
      <TT
CLASS="LITERAL"
>--termname=gnome</TT
>, for instance by suitably setting the
      command line in the launcher on the <SPAN
CLASS="ACRONYM"
>GNOME</SPAN
> panel. If
      however you have an old version, and this method does not work, you can
      add the lines
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;if [ "$COLORTERM" = "gnome-terminal" ]
then
    export TERM=gnome
fi</PRE
></FONT
></TD
></TR
></TABLE
>
to your <TT
CLASS="FILENAME"
>~/.bashrc</TT
> configuration file<A
NAME="AEN316"
HREF="#FTN.AEN316"
>[2]</A
>.  The assignment is executed
only under <SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
>, and sets correctly the
<TT
CLASS="ENVAR"
>TERM</TT
> variable.</P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Setting the terminal to <TT
CLASS="LITERAL"
>gnome</TT
> could prevent
<B
CLASS="COMMAND"
>ls</B
> from using colours, as many versions of
<B
CLASS="COMMAND"
>ls</B
> do not know that
<SPAN
CLASS="APPLICATION"
>gnome-terminal</SPAN
> is colour capable. To avoid this
problem, create a configuration file <TT
CLASS="FILENAME"
>~/.dircolors</TT
> with
<B
CLASS="COMMAND"
>dircolors --print-database &#62;~/.dircolors</B
>, and add a line
<TT
CLASS="USERINPUT"
><B
>TERM=gnome</B
></TT
> to the configuration file.</P
></TD
></TR
></TABLE
></DIV
><P
>We will now generate on-the-fly a suitable
<SPAN
CLASS="APPLICATION"
>termcap</SPAN
> entry for deviant terminal emulators; this
can be done as follows, always in <TT
CLASS="FILENAME"
>~/.bashrc</TT
>:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;if [ "$TERM" = "gnome" ]
then
    export TERMCAP=$(infocmp -C gnome | grep -v '^#' | \
                    tr '\n\t' '  ' | sed 's/\\  //g' | sed s/::/:/g)
fi</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>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
      <TT
CLASS="FILENAME"
>/etc/bashrc</TT
> that works: add this to
      <TT
CLASS="FILENAME"
>~/.bashrc</TT
>:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;KBS=$(tput kbs)
if [ ${#KBS} -eq 1 ]; then stty erase $KBS; fi</PRE
></FONT
></TD
></TR
></TABLE
>
It's a simple idea: we read from the terminal database the capability
<TT
CLASS="LITERAL"
>kbs</TT
>, and set the erase character to its value if it is a
single character (which happens in both standard and deviant terminals).</P
><DIV
CLASS="NOTE"
><P
></P
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Certain distributions could have fixes already in place in the
		  system-wide <TT
CLASS="FILENAME"
>/etc/inputrc</TT
> configuration file. In
		  this case you can eliminate redundant lines from your
		  <TT
CLASS="FILENAME"
>~/.inputrc</TT
>.</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN343">6.3. Fixing for <SPAN
CLASS="APPLICATION"
>tcsh</SPAN
></H2
><P
>In the case of the <SPAN
CLASS="APPLICATION"
>tcsh</SPAN
>, the fixes go
all in <TT
CLASS="FILENAME"
>~/.tcshrc</TT
>, and follow the same rationale as the ones for the
<SPAN
CLASS="APPLICATION"
>bash</SPAN
>:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;bindkey "^[[3~" delete-char

if ($?COLORTERM) then
   if ($COLORTERM == "gnome-terminal") then
      setenv TERM gnome
   endif
endif

if ($?TERM) then
   if ($TERM == "gnome") then
      setenv TERMCAP \
       "`infocmp -C gnome | grep -v '^#' | tr '\n\t' '  ' | sed 's/\\  //g' | sed s/::/:/g`"
      bindkey "^?" delete-char
      bindkey "^[^?" delete-word
      bindkey "\377" delete-word
   endif
endif

set KBS=`tput kbs`
if (${%KBS} == 1) then 
   stty erase $KBS
endif&#13;</PRE
></FONT
></TD
></TR
></TABLE
>
The second part must be replicated for every deviant terminal. Of course, if a
<SPAN
CLASS="APPLICATION"
>termcap</SPAN
> entry already exists it is not necessary to
generate it.</P
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.ADDINPUTRC"
HREF="system.html#ADDINPUTRC"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>On older
		version of the <SPAN
CLASS="APPLICATION"
>bash</SPAN
>, you must remember to set
		<TT
CLASS="ENVAR"
>INPUTRC</TT
> suitably, for instance adding
		<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>&#13;export INPUTRC=~/.inputrc</PRE
></FONT
></TD
></TR
></TABLE
> to your
		<TT
CLASS="FILENAME"
>~/.profile</TT
> (or whichever file is read just by login
		shells).</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN316"
HREF="system.html#AEN316"
>[2]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>More
precisely, to the shell configuration file that is read in every shell, not
only in login shells. The right file depend on startup sequence of your
<SPAN
CLASS="APPLICATION"
>bash</SPAN
>.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="writing.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="notwork.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>What You Should Do When Writing Applications</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>What If Nothing Works</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>