I've never seen anyone else with TCC have CPU usage incorporated into their prompt
Just kidding: I've never seen anyone else with TCC :)
I thought I'd share my
that I've been using for years. It's parameterized via setting environment variables. So then you can configure individual prompts in a separate BAT file without having to touch prompt-common and muck up the mess that it took to get the CPU in there.
I'd love to see a more elegant solution than mine. A lot of my stuff was slowly developed over 30 yrs in a very reactionary way and I'm trying to refactor a lot of it now to be less brittle.
[ignore the typo]
And here is the previous version, for pre-windows 10. I never did figure out why i had a failure when i moved to windows 10. I just resigned myself to let the old version of the BAT file die when i can safely assume i'm never going to run into a windows 7 machine ever again. (But in fact, there's one 10 feet away from me.)
Just kidding: I've never seen anyone else with TCC :)
I thought I'd share my
Code:
prompt-common.bat
I'd love to see a more elegant solution than mine. A lot of my stuff was slowly developed over 30 yrs in a very reactionary way and I'm trying to refactor a lot of it now to be less brittle.
[ignore the typo]
Code:
@Echo OFF
rem INVOCATION: Just run prompt-common.bat!
rem
rem But you can set environment variables to override default behavior, then run prompt-common
rem
rem
rem WAYS TO CHANGE THE DEFAULT BEHAVIOR:
rem set OS=95 (OS-specific behavior: set to 95,98,ME,2K,7,10,11 etc) [default behavior as of 2023 is Windows 10]
rem set SUPPRESS_LESSTHAN_BEFORE_PATH=0 (difference between "c:\>" [1] and "<c:\>" [0])
rem set ADD_THE_CPU_USAGE=0 (suppress adding CPU usage to prompt)
rem
rem WAYS TO CHANGE THE DEFAULT COLORS:
rem set CPU_USAGE_PERCENTS=0;32;33\
rem set CPU_USAGE_BRACKETS=0;32;33 \
rem set PATH_COLOR_THE_PAT=0;32;33 \
rem set PATH_COLOR_BRACKET=0;32;33 >--- Look below for example ANSI color codes
rem set TIME_COLOR_THE_TIM=0;32;33 /
rem set TIME_COLOR_BRACKET=0;32;33 /
rem set USER__TYPING__COLO=0;32;33/
rem ///// Branched to new version of this script with Windows 10, older OSes get the older version because I was really busy the day i was involuntarily force-upgraded to windows 10 -- old version is below
if "%OS" eq "95" .or. "%OS" eq "98" .or. "%OS" eq "ME" .or. "%OS" eq "2K" .or. "%OS" eq "7" (call prompt-common-pre-win10-fork.bat %* %+ goto :END)
rem ///// ANSI CONSTANTS (probably malformed, but work, so I never fixed them):
:: QUICK-REF: 1=BOLD;30=Black,31=Red,32=Green,33=Yellow,34=Blue,35=Purp,36=Cyan,37=White
set RED=1;31;31 %+ rem is this right?
set BRIGHT_RED=1;32;31 %+ rem is this right?
set YELLOW=0;32;33
set BRIGHT_YELLOW=1;32;33
set GREEN=0;32;32
set BRIGHT_GREEN=1;32;32
set BLUE=0;32;34
set BRIGHT_BLUE=1;32;34
set CYAN=0;32;36
set GRAY=1;30;30 %+ set GREY=%GRAY%
set WHITE=0;00;00
rem ///// DEFAULT COLORS THAT CAN BE OVERRIDDEN:
if not defined CPU_USAGE_PERCENTS set CPU_USAGE_PERCENTS=%YELLOW%
if not defined CPU_USAGE_BRACKETS set CPU_USAGE_BRACKETS=%GREEN% %+ rem %BRIGHT_YELLOW%
if not defined PATH_COLOR_THE_PATH set PATH_COLOR_THE_PATH=%BRIGHT_GREEN%
if not defined PATH_COLOR_BRACKETS set PATH_COLOR_BRACKETS=%GREEN%
if not defined TIME_COLOR_THE_TIME set TIME_COLOR_THE_TIME=%RED%
if not defined TIME_COLOR_BRACKETS set TIME_COLOR_BRACKETS=%BRIGHT_RED%
if not defined USER__TYPING__COLOR set USER__TYPING__COLOR=%WHITE%
rem ///// DEFAULT BEHAVIOR THAT CAN BE OVERRIDDEN:
if not defined ADD_THE_CPU_USAGE set ADD_THE_CPU_USAGE=1
if "%SUPPRESS_LESSTHAN_BEFORE_PATH%" ne "1" if not defined PATH_BRACKET_BEFORE set PATH_BRACKET_BEFORE=$l
rem ///// BUILD THE PROMPT:
:Setup
unset /q TMPPROMPT
:Add_Time_Of_Day
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_BRACKETS%m$L
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_THE_TIME%m$M
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_BRACKETS%m$G ``
:Add_CPU_Usage
REM DEBUG: call warning "`%`ADD_THE_CPU_USAGE is %ADD_THE_CPU_USAGE"
if %ADD_THE_CPU_USAGE ne 0 (
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_BRACKETS%m$L
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_PERCENTS%m CPUUSAGEHERE
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_BRACKETS%m$G ``
)
:Add_Path
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_BRACKETS%m%PATH_BRACKET_BEFORE%
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_THE_PATH%m$P
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_BRACKETS%m$G
:Add_Color_For_user_Typing
set TMPPROMPT=%TMPPROMPT%$e[%USER__TYPING__COLOR%m
rem ///// FORMAT/SBUSTITUTE/SET THE PROMPT:
if "%OS%" eq "2K" goto :CPU_Usage_Format_NO
if "%OS%" eq "XP" goto :CPU_Usage_Format_NO
if "%OS%" eq "10" goto :CPU_Usage_Format_YES_10
if "%OS%" eq "11" goto :CPU_Usage_Format_YES_10
goto :CPU_Usage_Format_YES_10 %+ REM Default behavior if %OS isn't set
:CPU_Usage_Format_YES
rem This one worked for years, maybe 10+, up until Windows 10 came out
prompt=%@REPLACE[ CPUUSAGEHERE,%%%%@FORMATN[02.0,%%%%[_CPUUsage]]%%%%%%%%,%[TMPPROMPT]]
goto :CPU_Usage_Format_DONE
:CPU_Usage_Format_YES_10
prompt=%%@REPLACE[ CPUUSAGEHERE,%%_CPUUSAGE%%%%%%%%%%,%[TMPPROMPT]]
goto :CPU_Usage_Format_DONE
:CPU_Usage_Format_NO
prompt=%@REPLACE[ CPUUSAGEHERE,%%%%[_CPUUsage]%%%%%%%%,%[TMPPROMPT]]
:CPU_Usage_Format_DONE
rem ///// CLEAN UP:
unset /q CPU_USAGE_PERCENTS
unset /q CPU_USAGE_BRACKETS
unset /q PATH_BRACKET_BEFORE
unset /q PATH_COLOR_THE_PATH
unset /q PATH_COLOR_BRACKETS
unset /q TIME_COLOR_THE_TIME
unset /q TIME_COLOR_BRACKETS
unset /q USER__TYPING__COLOR
unset /q SUPPRESS_LESSTHAN_BEFORE_PATH
:END
And here is the previous version, for pre-windows 10. I never did figure out why i had a failure when i moved to windows 10. I just resigned myself to let the old version of the BAT file die when i can safely assume i'm never going to run into a windows 7 machine ever again. (But in fact, there's one 10 feet away from me.)
Code:
.
NO DON'T LOOK AT THIS WHY ARE YOU STILL RUNNING WINDOWS 7 JUST STAHHHP
But if you must, scroll down.
@Echo OFF
::::: ANSI CONSTANTS (probably malformed, but work, so I never fixed them):
:: QUICK-REF: 1=BOLD;30=Black,31=Red,32=Green,33=Yellow,34=Blue,35=Purp,36=Cyan,37=White
set RED=1;31;31 %+ rem is this right?
set BRIGHT_RED=1;32;31 %+ rem is this right?
set YELLOW=0;32;33
set BRIGHT_YELLOW=1;32;33
set GREEN=0;32;32
set BRIGHT_GREEN=1;32;32
set BLUE=0;32;34
set BRIGHT_BLUE=1;32;34
set CYAN=0;32;36
set GRAY=1;30;30 %+ set GREY=%GRAY%
set WHITE=0;00;00
::::: DEFAULT COLORS THAT CAN BE OVERRIDDEN:
if not defined CPU_USAGE_PERCENTS set CPU_USAGE_PERCENTS=%YELLOW%
if not defined CPU_USAGE_BRACKETS set CPU_USAGE_BRACKETS=%GREEN% %+ rem %BRIGHT_YELLOW%
if not defined PATH_COLOR_THE_PATH set PATH_COLOR_THE_PATH=%BRIGHT_GREEN%
if not defined PATH_COLOR_BRACKETS set PATH_COLOR_BRACKETS=%GREEN%
if not defined TIME_COLOR_THE_TIME set TIME_COLOR_THE_TIME=%RED%
if not defined TIME_COLOR_BRACKETS set TIME_COLOR_BRACKETS=%BRIGHT_RED%
if not defined USER__TYPING__COLOR set USER__TYPING__COLOR=%WHITE%
::::: DEFAULT BEHAVIOR THAT CAN BE OVERRIDDEN:
if "%SUPPRESS_LESSTHAN_BEFORE_PATH%" ne "1" if not defined PATH_BRACKET_BEFORE set PATH_BRACKET_BEFORE=$l
if not defined ADD_THE_CPU_USAGE set ADD_THE_CPU_USAGE=1
::::: BUILD THE PROMPT:
:Setup
unset /q TMPPROMPT
:Add_Time_Of_Day
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_BRACKETS%m$L
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_THE_TIME%m$M
set TMPPROMPT=%TMPPROMPT%$e[%TIME_COLOR_BRACKETS%m$G ``
:ADD_THE_CPU_USAGE
if "%ADD_THE_CPU_USAGE%" eq "0" goto :ADD_THE_CPU_USAGE_NO
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_BRACKETS%m$L
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_PERCENTS%m%(CPUUSAGEHERE)
set TMPPROMPT=%TMPPROMPT%$e[%CPU_USAGE_BRACKETS%m$G ``
:ADD_THE_CPU_USAGE_NO
:Add_Path
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_BRACKETS%m%PATH_BRACKET_BEFORE%
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_THE_PATH%m$P
set TMPPROMPT=%TMPPROMPT%$e[%PATH_COLOR_BRACKETS%m$G
:Add_Color_For_user_Typing
set TMPPROMPT=%TMPPROMPT%$e[%USER__TYPING__COLOR%m
::::: FORMAT/SBUSTITUTE/SET THE PROMPT:
if "%OS%" eq "2K" goto :CPU_Usage_Format_NO
if "%OS%" eq "XP" goto :CPU_Usage_Format_NO
goto :CPU_Usage_Format_YES
:CPU_Usage_Format_YES
prompt=%@REPLACE[(CPUUSAGEHERE),%%%%@FORMATN[02.0%=,%%%%[_CPUUsage]]%%%%%%%%,%[TMPPROMPT]]
goto :CPU_Usage_Format_DONE
:CPU_Usage_Format_NO
prompt=%@REPLACE[(CPUUSAGEHERE),%%%%[_CPUUsage]%%%%%%%%,%[TMPPROMPT]]
:CPU_Usage_Format_DONE
::::: CLEAN UP:
unset /q CPU_USAGE_PERCENTS
unset /q CPU_USAGE_BRACKETS
unset /q PATH_BRACKET_BEFORE
unset /q PATH_COLOR_THE_PATH
unset /q PATH_COLOR_BRACKETS
unset /q TIME_COLOR_THE_TIME
unset /q TIME_COLOR_BRACKETS
unset /q USER__TYPING__COLOR
unset /q SUPPRESS_LESSTHAN_BEFORE_PATH