old-www/LDP/LG/issue14/bashtip.html

121 lines
4.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Novice Bash Tip Issue 14</title>
</HEAD>
<BODY >
<H4>
&quot;Linux Gazette...<I>making Linux just a little more lovable!</I>&quot;
<IMG ALIGN=MIDDLE SRC="../gx/heart.gif"> </H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H2>Novice Bash Tip -- Edit command-lines &quot;joe-style&quot;</H2>
<H4>By Joel Wilf,
<a href="mailto:av293@lafn.org">av293@lafn.org</a></H4>
</center>
<P> <HR> <P>
If like me, you come from the world of DOS and WordStar, you
feel right at home with the joe editor, which uses WordStar
keystrokes.
<P>
But as soon as you exit joe, you're back in the land of bash,
where command-lines are edited &quot;emacs-style.&quot; Soon,
your fingers are confused. Before you know it, you're pressing
&lt;control&gt;-d to move the cursor, only to find your command-line
disappearing.
<P>
But why use one set of keys to edit text and another to edit
commands? The beauty of Linux is that you can customize it to
your heart's content. Here's how to make bash act like our old
friend, joe:
<P>
<H3>Step 1: define keys with .inputrc:</H3>
<P>
The bash command-line is handled by the GNU readline library. So
it's not surprising that bash uses the same keystrokes as GNU
emacs. Luckily, you can change these key-bindings simply by
setting new values in the file .inputrc.
<P>
The first step is to go to your $HOME directory and open or
create a text file named .inputrc. Then add the following
lines, which tell bash to use the basic joe keystrokes:
<PRE> <h5>
"\C-d": forward-char
"\C-s": backward-char
"\C-f": forward-word
"\C-a": backward-word
"\C-g": delete-char
"\C-t": kill-word
"\C-y": kill-whole-line
</h5> </PRE>
You can also add the following lines, which fix the behavior of
the &lt;home&gt;, &lt;end&gt;, &lt;delete&gt;, and &lt;backspace&gt;
keys:
<PRE> <h5>
"\e[1~": beginning-of-line
"\e[3~": delete-char
"\e[4~": end-of-line
DEL: backward-delete-char
</h5> </PRE>
Finally, you can use .inputrc to modify any one of the dozens of
keystrokes and variables that control bash. (Among other
things, you can get bash to stop beeping at you!) Check the
READLINE section of the bash man page for details.
<P>
<H3>Step 2: fix terminal settings with stty:</H3>
<P>
An experienced Linuxer will see that the changes we made to
.inputrc has created a problem. We set &lt;control&gt;-s to
it's WordStar meaning. But the Linux terminal uses
&lt;control&gt;-s to send the &quot;stop&quot; signal.
Pressing &lt;control&gt;-s freezes the terminal until you type
&lt;control&gt;-q, the &quot;start&quot; signal.
<P>
The easiest way to fix this is to tell the terminal to use a
different &quot;stop&quot; key. To reassign &quot;stop&quot; to
&lt;control&gt;-p, type the following line (and put it in your
.bashrc to make it permanent):
<PRE> <h5>
stty stop '^p'
</h5> </PRE>
You can prove this works by pressing &lt;control&gt;-p then
&lt;control&gt;-q. It's also a good idea to check your terminal
configuration -- especially if you change other keys with
.inputrc. Type:
<PRE> <h5>
stty -a
</h5> </PRE>
This will display your terminal settings. If you reassigned the
&quot;stop&quot; key as shown above, you should see &quot;stop = ^P&quot;.
<P>
Now you're home free. All you have to do is exit and log in
again. And you can edit commands &quot;joe-style.&quot;
<P>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1997, Joel Wilf <BR>
Published in Issue 14 of the Linux Gazette</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./shells.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./vim.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</BODY>
</HTML>