John Murray · Apr 7, 2017 1m read

"Where am I?" - Adding extra information to the Terminal prompt

If you deal with multiple instances of Caché / Ensemble / HealthShare and sometimes have to work at the Terminal command prompt, did you know that you can easily add extra information to that prompt which may help prevent you running a command on the wrong instance?

The format of the command prompt is controlled by the TerminalPrompt setting in the [Startup] section of the CPF but it is normally manipulated via Portal. The documentation is here.

The default prompt looks like this:

USER>; TerminalPrompt="8,2"

The 2 is what provides the namespace name. Most of the time the 8 adds nothing, but you can see its effect by starting a transaction or two, then ending them:


When working with multiple instances, perhaps across different servers, setting TerminalPrompt="8,1,3,2" may be useful:

Node: TIN, Instance: ENS171
TIN:ENS171:USER>; TerminalPrompt="8,1,3,2"

0 453
Discussion (3)0
Log in or sign up to continue

To check new prompt $system.Process method can be used:

do $system.Process.TerminalPrompt(8,2,4)

Here's a description of all possible values. For me 4 (Current time) is very useful as it allows for a quick performance tracking.

And if you want to make your own prompt, you could even use your own Shell routine :

Shell ;
    For {
        Try {
            Write !,$$Prompt()
            Read cmd Write !
            Xecute cmd
        } Catch {
            Write $ZE,!
        If ($ZCVT($G(cmd),"U")="QUIT") Quit

Prompt() ;Create your own prompt here !
    New prompt
    Set prompt = $ZDate($H,4)_" - "_$ZTime($P($H,",",2))_" > "
    Quit prompt

Be aware that by fetching $H twice there's a small possibility of an unwanted outcome. For example, consider what happens if the first time it returns "64382,86399" and the second time "64383,0". Harmless in Danny's prompt code, but in other contexts it could cause problems.