PROMPT

Print Topic  Return to Overview  Previous Topic  Next Topic 
Purpose:Change the command line prompt.

 

Format:PROMPT [text]

 

text Text to be used as the new command line prompt.

 

See also:    ESET and SET (the PROMPT command is syntactically equivalent to SET PROMPT).

 

Usage:

 

You can change and customize the command line prompt at any time. The prompt can include normal text and system information such as the current drive and directory, the time and date, and the amount of memory available. You can create an informal "Hello, Bob!" prompt or a complex prompt full of impressive information.

 

The prompt text can contain special commands in the form $?, where ? is one of the characters listed below. Unless otherwise specified, those meta characters are case-independent.

 

aThe ampersand character[&].
bThe vertical bar character [|].
cThe open parenthesis [(].
dCurrent date, in the format:  Fri 12-28-07 (the month, day, and year are formatted according to your current country settings)
DCurrent date, in the format:  Fri Dec 28, 2007
eThe ASCII ESC character (decimal 27), necessary for ANSI commands.
fThe close parenthesis [)].
gThe > character.
hBackspace over the previous character.
jCurrent date in ISO 9601 format (yyyy-mm-dd).
lThe < character.
mTime in hours and minutes using 24-hour format.
MTime in hours and minutes using the default country format.
nCurrent drive letter.
pCurrent drive and directory (lower case).
PCurrent drive and directory (upper case on drives which do not support long filenames; directory names shown in mixed case as stored on the disk on LFN drives).
qThe = character.
rThe numeric exit code of the last external command.
sThe space character.
tCurrent 24-hour time, in the format hh:mm:ss.
TCurrent 12-hour time, in the format hh:mm:ss[a|p).
uThe current user.
vWindows version number, in the format 6.0.
wCurrent directory, in a shortened format. If the current directory is the root or a first-level subdirectory, it is displayed as-is. If it is second level or deeper, the path is truncated (i.e., "c:\…\config"). (This does not work with UNC names.) $W and $w behave like $P and $p for displaying upper/lower case.
xd:Current directory on drive d: in lower case, including the drive letter (uses the actual case of the directory name as stored on the disk for LFN drives.)
Xd:Current directory on drive d: in upper case, including the drive letter.
zCurrent shell nesting level.
+Display one + character for each directory on the PUSHD directory stack.
$The $ character.
_CR/LF (go to beginning of a new line).

 

For example, to set the prompt to the current date and time, with a ">" at the end:

 

[c:\] prompt $d $t $g

Thu  Sep 30, 2004 10:29:19 >

 

The TCC prompt can be set in TCSTART or in any batch file that runs when TCC starts.

 

If you enter PROMPT with no parameters, the prompt will be reset to its default value.

 

You can include literal text and special characters as well as the value of any environment variable, internal variable, or variable function in a prompt. For example, if you want to include the size of the largest free memory block in the command prompt, plus the current drive and directory, you could use this command:

 

[c:\] prompt [(%%@dosmem[K]K) $p]

[(31043K) c:\data]

 

Notice that the @DOSMEM function is shown with two leading percent signs [%]. If you used only one percent sign, the @DOSMEM function would be expanded at once when the PROMPT command was executed, instead of every time the prompt is displayed. As a result, the amount of memory would never change from the value it had when you entered the PROMPT command. You can also use back quotes to delay expanding the variable function until the prompt is displayed:

 

prompt `[(%@dosmem[K]K) $p]`

 

You can use this feature along with the @EXEC variable function to create a complex prompt which not only displays information but executes commands. For example, to execute an alias which checks battery status each time the prompt is displayed (enter the alias on one line):

 

alias cbatt `if %_apmlife lt 30 beep 440 4 880 4 440 4 880 4`

prompt `%@exec[@cbatt]$p$g`

 

You can include ANSI escape sequences in the PROMPT by using the built-in ANSI X3.64 support in TCC. This example uses ANSI X3.64 sequences to set a prompt that displays the shell level, date, time and path in color on the top line of the screen (enter the command as one line):

 

prompt $e[s$e[1;1f$e[41;1;37m$e[K[$z] $d 

Time: $t$h$h$h  Path: $p$e[u$e[0;32m$n$g

 

You may find it helpful to define a different prompt in secondary shells, perhaps including $z in the prompt to display the shell level. To do so, place a PROMPT command in your TCSTART file and use IF, IFF, or SWITCH statements to set the appropriate prompt for different shells.

 

Topic "prompt.htm" last edited 4/27/2008. ©2008  JP Software, Inc.
Keywords: PROMPT,Metacharacters,$ metacharacter