Last active
December 19, 2025 15:34
-
-
Save tnhung2011/75bcef9c24f58980dd031e622c3da300 to your computer and use it in GitHub Desktop.
A CLI for arithmetic operations, with floating-point support via JScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @if (@X == @Y) @end /* | |
| @echo off | |
| setlocal enableextensions enabledelayedexpansion | |
| for /f %%A in ('prompt $H ^&echo on ^&for %%B in ^(1^) do rem') do set bs=%%A | |
| set ansi1= | |
| set ansi2= | |
| 2>nul >nul (reg query HKCU\Console /v VirtualTerminalLevel /t REG_DWORD | find "0x1") && ( | |
| set ansi1=[1;33m | |
| set ansi2=[0m | |
| ) | |
| :banner | |
| echo %ansi1%Usage:%ansi2% https://ss64.com/nt/set.html#expressions | |
| echo %ansi1%Extras:%ansi2% _ =^> last evaluated expression | |
| echo %bs% cls =^> clear the screen | |
| echo %bs% exit =^> exit the CLI | |
| echo %bs% ^<Floats are supported using JScript^> | |
| set bs= | |
| set ansi1= | |
| set ansi2= | |
| ::set default value so that string replacement doesn't give bogus results | |
| set _=0 | |
| :input | |
| set /p _input=^> || goto input | |
| if "%_input%"=="cls" (cls & goto input) | |
| if "%_input%"=="exit" (exit /b) | |
| set arith=/a | |
| if not "%_:*.=%"=="%_%" goto cscript | |
| for %%i in (NaN Infinity) do if not "!_input:*%%i=!"=="%_input%" goto cscript | |
| if not "%_input:*.=%"=="%_input%" ( | |
| if not "%_input:**=%"=="%_input%" goto cscript | |
| for %%i in (+ - / %% ! ~ ^& ^| ^^ ^<^< ^>^>) do if not "!_input:*%%i=!"=="%_input%" goto cscript | |
| set arith= | |
| ) | |
| set %arith% "_=!_input!" | |
| goto print | |
| :cscript | |
| for /f "tokens=*" %%a in ('cscript //nologo //e:jscript "%~f0"') do set _=%%a | |
| echo:%_% | |
| goto input | |
| */ | |
| var procenv = WScript.CreateObject("WScript.Shell").Environment("Process"); | |
| var _ = Number(procenv.Item("_")); | |
| var _input = procenv.Item("_input"); | |
| if (/^([0-9\.\+\-*%!~&\|^\/_\s\t]|<<|>>|Infinity|NaN)*$/.test(_input)) WScript.Echo(eval(_input)); | |
| else WScript.Echo("Invalid expression or environment variables not supported (in JScript)."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment