342 lines
5.3 KiB
HTML
342 lines
5.3 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Saving Complex Prompts</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Bash Prompt HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="What to Put in Your Prompt"
|
|
HREF="x295.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="ANSI Escape Sequences: Colours and Cursor Movement"
|
|
HREF="c327.html"></HEAD
|
|
><BODY
|
|
CLASS="CHAPTER"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Bash Prompt HOWTO: </TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x295.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
></TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="c327.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="CHAPTER"
|
|
><H1
|
|
><A
|
|
NAME="SAVING-COMPLEX-PROMPTS"
|
|
></A
|
|
>Chapter 5. Saving Complex Prompts</H1
|
|
><P
|
|
>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: <A
|
|
HREF="the-bash-prompt-package.html"
|
|
>Chapter 8</A
|
|
>), 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: </P
|
|
><TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>#!/bin/bash
|
|
|
|
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
|
|
xterm*|rxvt*)
|
|
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
|
|
;;
|
|
*)
|
|
TITLEBAR=""
|
|
;;
|
|
esac
|
|
|
|
PS1="$TITLEBAR\
|
|
$YELLOW-$LIGHT_BLUE-(\
|
|
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\
|
|
$LIGHT_BLUE)-(\
|
|
$YELLOW\$PWD\
|
|
$LIGHT_BLUE)-$YELLOW-\
|
|
\n\
|
|
$YELLOW-$LIGHT_BLUE-(\
|
|
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \"+%a,%d %b %y\")\
|
|
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR "
|
|
|
|
PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR "
|
|
|
|
} </PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><P
|
|
>You can work with it as follows: </P
|
|
><TABLE
|
|
BORDER="1"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>[giles@nikola:/bin (4.498 Mb)]$ cd <A
|
|
NAME="CD"
|
|
><IMG
|
|
SRC="../images/callouts/1.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(1)"></A
|
|
>
|
|
[giles@nikola:~ (0 Mb)]$ vim tonka <A
|
|
NAME="VIM"
|
|
><IMG
|
|
SRC="../images/callouts/2.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(2)"></A
|
|
>
|
|
... <A
|
|
NAME="EDIT"
|
|
><IMG
|
|
SRC="../images/callouts/3.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(3)"></A
|
|
>
|
|
[giles@nikola:~ (0 Mb)]$ source tonka <A
|
|
NAME="SOURCE"
|
|
><IMG
|
|
SRC="../images/callouts/4.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(4)"></A
|
|
>
|
|
[giles@nikola:~ (0 Mb)]$ tonka <A
|
|
NAME="EXECUTE"
|
|
><IMG
|
|
SRC="../images/callouts/5.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(5)"></A
|
|
>
|
|
[giles@nikola:~ (0 Mb)]$ unset tonka <A
|
|
NAME="UNSET"
|
|
><IMG
|
|
SRC="../images/callouts/6.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(6)"></A
|
|
></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><DIV
|
|
CLASS="CALLOUTLIST"
|
|
><DL
|
|
COMPACT="COMPACT"
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#CD"
|
|
><IMG
|
|
SRC="../images/callouts/1.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(1)"></A
|
|
></DT
|
|
><DD
|
|
>Move to the directory where you want to save the prompt</DD
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#VIM"
|
|
><IMG
|
|
SRC="../images/callouts/2.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(2)"></A
|
|
></DT
|
|
><DD
|
|
>Edit the prompt file with your preferred editor</DD
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#EDIT"
|
|
><IMG
|
|
SRC="../images/callouts/3.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(3)"></A
|
|
></DT
|
|
><DD
|
|
>Enter the prompt text given above as "tonka"</DD
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#SOURCE"
|
|
><IMG
|
|
SRC="../images/callouts/4.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(4)"></A
|
|
></DT
|
|
><DD
|
|
>Read the prompt function into the environment</DD
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#EXECUTE"
|
|
><IMG
|
|
SRC="../images/callouts/5.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(5)"></A
|
|
></DT
|
|
><DD
|
|
>Execute the prompt function</DD
|
|
><DT
|
|
><A
|
|
HREF="saving-complex-prompts.html#UNSET"
|
|
><IMG
|
|
SRC="../images/callouts/6.gif"
|
|
HSPACE="0"
|
|
VSPACE="0"
|
|
BORDER="0"
|
|
ALT="(6)"></A
|
|
></DT
|
|
><DD
|
|
>Optionally, unclutter your environment by unsetting the function</DD
|
|
></DL
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x295.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c327.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>What to Put in Your Prompt</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
> </TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>ANSI Escape Sequences: Colours and Cursor Movement</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |