NOTE: This is a re-post of a message originally posted July 10, 2000. This
should probably go into a FAQ, mini-HOWTO, or other collection of nifty LRP
tricks...
I have been wanting to get the current directory output as part of my
command
prompt for some time, but the ash shell that comes with LRP does not do any
bash type prompt expansion (date, time, current directory, etc..). In
trying
to get this to work, I have hit upon a method that seems like a handy way to
use shell scripts to add commands that modify the existing shell. A
conventional script, by contrast, is run in a sub-shell, and when it exits,
any changes die with it...
The secret lies in defining functions at the root shell level and using
alias
to substute the new function for an acutal command. This can be done by
adding a function to the shell profile file in the users home directory
(/root/.profile for the standard root account), or in the /etc/profile
directory (changes will impact all users).
To start, make a function definition that does what you want. In this case,
the funcion should change directories, then update the prompt with directory
information. My function looks like this:
cdprompt () {
command cd $@
PS1=`echo -n -e "\n$HOSTNAME: -$USER-\n$PWD # "`
}
NOTE: What would normally be just a 'cd' in the above script is 'command
cd',
which tells ash to override any alias settings and use the built-in command.
If you are overriding an external program/script, you would specify the
explicit path.
Next, you need to make substutite the new function for the cd command, using
alias:
alias cd=cdprompt
If you add both of these lines to /etc/profile or /root/.profile and backup,
your prompt will include the current directory ($PWD in the prompt string
above). You could similarly add the output of date, mem, or any other
commands with a suitable cdprompt function.
NOTE: Your command prompt and actual working directory can get out of sync.
This happens on bootup, as the shell prompt setting is used and not updated
until you do a 'cd'. This could also happen if you run a program other than
cd that changes your directory. As soon as you do a cd, the command prompt
will be updated.
I hope you find this useful,
Charles Steinkuehler
http://lrp.steinkuehler.net
http://c0wz.steinkuehler.net (lrp.c0wz.com mirror)
_______________________________________________
Leaf-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/leaf-user