(M)  s i s t e m a   o p e r a c i o n a l   m a g n u x   l i n u x ~/ · documentação · suporte · sobre

  Next Previous Contents

9. Loading a Different Prompt

9.1 Loading a Different Prompt, Later

The explanations in this HOWTO have shown how to make PS1 environment variables, or how to incorporate those PS1 and PS2 strings into functions that could be called by ~/.bashrc or as a theme by the bashprompt package.

Using the bashprompt package, you would type bashprompt -i to see a list of available themes. To set the prompt in future login shells (primarily the console, but also telnet and Xterms, depending on how your Xterms are set up), you would type bashprompt -l themename. bashprompt then modifies your ~/.bash_profile to call the requested theme when it starts. To set the prompt in future subshells (usually Xterms, rxvt, etc.), you type bashprompt -s themename, and bashprompt modifies your ~/.bashrc file to call the appropriate theme at startup.

See also Setting the PS? Strings Permanently for Johan Kullstam's note regarding the importance of putting the PS? strings in ~/.bashrc .

9.2 Loading a Different Prompt, Immediately

You can change the prompt in your current terminal (using the example "elite" function above) by typing "source elite" followed by "elite" (assuming that the elite function file is the working directory). This is somewhat cumbersome, and leaves you with an extra function (elite) in your environment space - if you want to clean up the environment, you would have to type "unset elite" as well. This would seem like an ideal candidate for a small shell script, but a script doesn't work here because the script cannot change the environment of your current shell: it can only change the environment of the subshell it runs in. As soon as the script stops, the subshell goes away, and the changes the script made to the environment are gone. What can change environment variables of your current shell are environment functions. The bashprompt package puts a function called "callbashprompt" into your environment, and, while they don't document it, it can be called to load any bashprompt theme on the fly. It looks in the theme directory it installed (the theme you're calling has to be there), sources the function you asked for, loads the function, and then unsets the function, thus keeping your environment uncluttered. "callbashprompt" wasn't intended to be used this way, and has no error checking, but if you keep that in mind, it works quite well.


Next Previous Contents