Chapter 5. Saving Complex Prompts

As the prompts you use become more complex, it becomes more and more cumbersome to type them in at the prompt, and more practical to make them into some sort of text file. I have adopted the method used by the Bashprompt package (discussed later in this document: Chapter 8), which is to put the primary commands for the prompt in one file with the PS1 string in particular defined within a function of the same name as the file itself. It's not the only way to do it, but it works well. Take the following example:


function tonka {

#   Named "Tonka" because of the colour scheme

local WHITE="\[\033[1;37m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local YELLOW="\[\033[1;33m\]"
local NO_COLOUR="\[\033[0m\]"

case $TERM in

$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \"+%a,%d %b %y\")\



You can work with it as follows:

[giles@nikola:/bin (4.498 Mb)]$ cd      (1)
[giles@nikola:~ (0 Mb)]$ vim tonka      (2)
...                                     (3) 
[giles@nikola:~ (0 Mb)]$ source tonka   (4)
[giles@nikola:~ (0 Mb)]$ tonka          (5)
[giles@nikola:~ (0 Mb)]$ unset tonka    (6)
Move to the directory where you want to save the prompt
Edit the prompt file with your preferred editor
Enter the prompt text given above as "tonka"
Read the prompt function into the environment
Execute the prompt function
Optionally, unclutter your environment by unsetting the function