|
Next
Previous
Contents
4. Examples for different shellsBelow we provide an set of examples for some of the more common shells.
We start with
In all the examples we test the environment variable
We should make an extra comment about C shell derivatives, such as
(In our opinion this is just one of many reasons not to use C shells. See
Csh Programming Considered Harmful for a useful
discussion).
The examples below should be used by inserting them into the appropriate
shell initialisation file; i.e. one that is sourced by interactive shells
on startup. In most cases this is called something like
4.1 zsh
There are many more expansions available: see the zshmisc man page.
Thus, the following will set the xterm title to
"
This could also be achieved by using chpwd() instead
of precmd(). The print builtin works like
echo, but gives us access to the % prompt escapes.
4.2 tcsh
Unfortunately, there is no equivalent to
However, this gives the directory's full path instead of using ~.
Instead you can insert the string in the prompt:
which sets a prompt of "tcsh% ", and an xterm title and icon
of "username@hostname: directory". Note that
the "%{...%}" must be placed around escape sequences (and cannot
be the last item in the prompt: see the tcsh man page for details).
4.3 bash
where \033 is the character code for ESC,
and \007 for BEL.
Note that the quoting is important here: variables are expanded in
However,
Thus, the following produces a prompt of
Note the use of \[...\], which tells bash to ignore
the non-printing control characters when calculating the width
of the prompt. Otherwise line editing commands get confused while
placing the cursor.
4.4 ksh
However, $PWD produces the full directory path. We can remove the
prefix of $HOME/ from the directory using the ${...##...}
construct. We can also use ${...%%...} to truncate the hostname:
Note that the ^[ and ^G in the prompt string are single
characters for ESC and BEL (can be entered in emacs
using C-q ESC and C-q C-g).
4.5 cshThis is very difficult indeed in
where we have had to alias the cd command to do the work of
sending the escape sequence. Note that the ^[ and ^G in
the string are single characters for ESC and BEL
(can be entered in emacs using C-q ESC and C-q C-g).
Notes: on some systems
Next Previous Contents Linux HOWTO full list |
|
This document, LDP HOWTO-INDEX, is copyrighted (c) 1995 - 2002 by Tim Bynum, Guylhem Aznar, Joshua Drake and Greg Ferguson. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html. If you have questions, please contact the LDP.
Web Design Copyright © 1999-2003. Chrisranjana Software Solutions Pvt Ltd. syndicate rss feed |