home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 7.5 Multiline Shell Prompts Chapter 7
Setting Your Shell Prompt
Next: 7.7 A "Menu Prompt" for Naive Users
 

7.6 Session Information in Your Terminal's Status Line

Some people don't like to put the current directory, hostname, etc. into their prompts because it makes the screen look cluttered to them. Here's another idea. If your terminal or window system has a status line or title bar, you might be able to put the information there. That's nice because you'll be able to see the information while you run programs. The bad side is that the information can get out-of-date if you use a command that takes you to another host or directory without updating the status line.

When you cd , an alias uses the echo command to write special escape sequences (5.8 ) (terminal commands) to the terminal or window.

Here's a cd alias and other commands for your .cshrc file. If I were logged in to www.jpeek.com in the directory /home/jpeek , this alias would put:

www:/home/jpeek

in the status area. Of course, you can change the format of the status line. Change the command string below, ${host:h}:${cwd} , to do what you need.

echo...033
 






&&
 
set e="`echo -n x | tr x \\033`"   # Make an ESCape character


set host=`uname -n`
# Puts $host and $cwd in VT102 status line. Escape sequences are:
# ${e}7 = save cursor position, ${e}[25;1f = go to start of status
# line (line 25), ${e}[0K = erase line, ${e}8 = restore cursor
alias cd 'chdir \!* && \\
   echo -n "${e}7${e}[25;1f${e}[0K    ${host:h}:${cwd}${e}8"'

If you always use a VT102-type terminal (and many people do), that alias will work fine. If you use a different terminal, read its manual or its termcap /terminfo entry (41.11 ) and find the escape sequences that work for it.

People who use more than one type of terminal, that aren't all VT102-compatible, can add a case (44.5 ) or switch (47.6 ) to test the terminal type and use a cd alias written for that terminal. (The alias can also put the status information in the shell prompt on terminals that don't have a status line.) But you might have some trouble: if the alias is defined in your .cshrc file but your terminal type is set in your .login file, the terminal type may not be set until after the alias has been read. There are workarounds (2.7 ) .

The status line can also get out of sync with reality if you use remote logins (1.33 ) , subshells (38.4 ) , and other things. These might put a new prompt in the status line but not reset the original prompt when it should be reset. The easiest workaround for this is by using the command below to change directory to the current directory (. ) and reset the status line:

% cd .

- JP


Previous: 7.5 Multiline Shell Prompts UNIX Power Tools Next: 7.7 A "Menu Prompt" for Naive Users
7.5 Multiline Shell Prompts Book Index 7.7 A "Menu Prompt" for Naive Users

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System