A simple command counter

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
Code:
rem  1.  Create a variable to hold the count:
set ncmd=0

rem  2.  Show this variable in the prompt:
prompt `[%ncmd] $P$g`

rem  3.  Increment the count after each command:
alias post_exec=`set ncmd=%@inc[%ncmd]`

Note the use of backquotes to prevent variables and functions from being expanded prematurely.
 
  • Like
Reactions: hughntx

samintz

Scott Mintz
May 20, 2008
1,557
26
Solon, OH, USA
As an FYI, you don't need the inner %ncmd as @eval and @inc/@dec expect that to be a variable.
Code:
alias post_exec=`set ncmd=%@inc[ncmd]`
 
Many, many years ago, back when I was using 4DOS, it was either Charles or Rex who provided me with a method to "imitate" the bash shell prompt, giving a prompt that shows the command count. I am still using it.

I have an alias defined as;
Code:
plc=set plc=%@inc[%plc]

In my 4start.btm, I have;
Code:
PROMPT=`%_cmdproc:%_pid:%@exec[@plc] %plc $g `

Joe