Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
554 changes: 554 additions & 0 deletions .github/skills/batch-files/SKILL.md

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions .github/skills/batch-files/assets/executable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
@echo off
REM myTool
:: A standalone command-line tool template with argument parsing.
::
:: usage: myTool [options] [1] [2]
:: [1] = input file path or value
:: [2] = output file path (optional)
::
:: options:
:: /? Show this help message
:: -h Show this help message
:: --help Show this help message
:: -v Show version information
:: --verbose Enable verbose output
::
:: examples:
:: > myTool "C:\data\input.txt"
:: > myTool "C:\data\input.txt" "C:\data\output.txt"
:: > myTool --verbose "C:\data\input.txt"
::
set "_helpLinesMyTool=19"

:: ========================================================================
:: TEMPLATE INSTRUCTIONS
:: 1. Find/Replace "myTool" with your executable name (camelCase).
:: 2. Find/Replace "MyTool" with your executable name (PascalCase).
:: 3. Update the help block above (lines 2-19) for your tool.
:: 4. Implement your logic in :_runMyTool.
:: 5. Add any new variables to :_removeBatchVariablesMyTool.
:: ========================================================================

:: Config variables.
set "_versionMyTool=1.0.0"
set "_verboseMyTool=0"

:: Define paths.
set "_scriptDirMyTool=%~dp0"
set "_scriptNameMyTool=%~n0"

:: Parse arguments into variables.
set "_parOneMyTool=%~1"
set "_checkParOneMyTool=-%_parOneMyTool%-"
set "_parTwoMyTool=%~2"
set "_checkParTwoMyTool=-%_parTwoMyTool%-"
set "_parThreeMyTool=%~3"
set "_checkParThreeMyTool=-%_parThreeMyTool%-"

:: -----------------------------------------------------------------------
:: Handle help and version flags.
:: -----------------------------------------------------------------------
if "%_parOneMyTool%"=="/?" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
if /i "%_parOneMyTool%"=="-h" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
if /i "%_parOneMyTool%"=="--help" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
Comment on lines +51 to +53
if /i "%_parOneMyTool%"=="-v" (
echo %_scriptNameMyTool% version %_versionMyTool%
goto _removeBatchVariablesMyTool
)

:: -----------------------------------------------------------------------
:: Handle --verbose flag (shift arguments if present).
:: -----------------------------------------------------------------------
if /i "%_parOneMyTool%"=="--verbose" (
set "_verboseMyTool=1"
set "_parOneMyTool=%~2"
set "_checkParOneMyTool=-%~2-"
set "_parTwoMyTool=%~3"
set "_checkParTwoMyTool=-%~3-"
)

:: Create temp directory for intermediate files.
call :_makeTempDirMyTool

:: -----------------------------------------------------------------------
:: Validate required input and start execution.
:: -----------------------------------------------------------------------
if "%_checkParOneMyTool%"=="--" (
echo ERROR: No input specified. Run "%_scriptNameMyTool% /?" for usage. 1>&2
goto _removeBatchVariablesMyTool
)

call :_startMyTool
goto _removeBatchVariablesMyTool

:: ========================================================================
:: MAIN LOGIC
:: ========================================================================

:_startMyTool
if "%_verboseMyTool%"=="1" (
echo [VERBOSE] Input: %_parOneMyTool%
echo [VERBOSE] Output: %_parTwoMyTool%
)

REM Validate input file exists.
if NOT EXIST "%_parOneMyTool%" (
echo ERROR: Input file not found: %_parOneMyTool% 1>&2
goto :eof
)

call :_runMyTool
goto :eof

:_runMyTool
REM ===================================================================
REM TODO: Replace this section with your tool's logic.
REM ===================================================================
echo Processing: %_parOneMyTool%

if NOT "%_checkParTwoMyTool%"=="--" (
echo Output to: %_parTwoMyTool%
REM Example: copy input to output.
REM copy /Y "%_parOneMyTool%" "%_parTwoMyTool%" >nul
)

echo Done.
goto :eof

:: ========================================================================
:: SUPPORT FUNCTIONS
:: ========================================================================

:_showHelpMyTool
echo:
for /f "skip=1 delims=" %%a in ('findstr /n "^" "%~f0"') do (
set "_line=%%a"
setlocal EnableDelayedExpansion
for /f "delims=:" %%n in ("!_line!") do set "_lineNum=%%n"
if !_lineNum! GTR %_helpLinesMyTool% (
endlocal
goto :eof
)
set "_text=!_line:*:=!"
if defined _text (
echo !_text:~4!
) else (
echo:
)
endlocal
)
goto :eof

:_makeTempDirMyTool
set "_tmpDirMyTool=%TEMP%\%~n0_%RANDOM%%RANDOM%"
set "_tmpDirCreatedMyTool=0"
if NOT EXIST "%_tmpDirMyTool%" (
mkdir "%_tmpDirMyTool%" >nul 2>nul
set "_tmpDirCreatedMyTool=1"
)
goto :eof

:: ========================================================================
:: CLEANUP — Remove all batch variables.
:: ========================================================================
:_removeBatchVariablesMyTool
set _helpLinesMyTool=
set _versionMyTool=
set _verboseMyTool=
set _scriptDirMyTool=
set _scriptNameMyTool=
set _parOneMyTool=
set _checkParOneMyTool=
set _parTwoMyTool=
set _checkParTwoMyTool=
set _parThreeMyTool=
set _checkParThreeMyTool=
REM Append new variables above this line.

if "%_tmpDirCreatedMyTool%"=="1" if EXIST "%_tmpDirMyTool%" rmdir /S /Q "%_tmpDirMyTool%" >nul 2>nul
set _tmpDirMyTool=
set _tmpDirCreatedMyTool=
exit /b
188 changes: 188 additions & 0 deletions .github/skills/batch-files/assets/library.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
@echo off
REM myLib
:: A reusable function library with CALL-able labels.
::
:: usage: call myLib [function] [args...]
:: Functions:
:: trimWhitespace [inputVar] Trim leading/trailing spaces
:: toLower [inputVar] Convert value to lowercase
:: getTimestamp [outputVar] Get current date-time stamp
:: logMessage [level] [message] Write a log entry
:: padRight [string] [width] Right-pad a string with spaces
::
:: examples:
:: > set "myVar= Hello World "
:: > call myLib trimWhitespace myVar
:: > call myLib getTimestamp _now
:: > call myLib logMessage INFO "Acme Corp backup started"
::
set "_helpLinesMyLib=17"

:: ========================================================================
:: TEMPLATE INSTRUCTIONS
:: 1. Find/Replace "myLib" with your library name (camelCase).
:: 2. Find/Replace "MyLib" with your library name (PascalCase).
:: 3. Add your own :_funcNameMyLib labels below.
:: 4. Update the help block above (lines 2-17) for your library.
:: 5. Add any new variables to :_removeBatchVariablesMyLib.
:: ========================================================================

:: Route to the requested function.
set "_funcMyLib=%~1"
set "_argOneMyLib=%~2"
set "_argTwoMyLib=%~3"
set "_argThreeMyLib=%~4"

if "%_funcMyLib%"=="/?" call :_showHelpMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="-h" call :_showHelpMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="--help" call :_showHelpMyLib & goto _removeBatchVariablesMyLib

if /i "%_funcMyLib%"=="trimWhitespace" call :_trimWhitespaceMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="toLower" call :_toLowerMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="getTimestamp" call :_getTimestampMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="logMessage" call :_logMessageMyLib & goto _removeBatchVariablesMyLib
if /i "%_funcMyLib%"=="padRight" call :_padRightMyLib & goto _removeBatchVariablesMyLib
Comment on lines +36 to +44

echo ERROR: Unknown function "%_funcMyLib%". Run "%~n0 /?" for usage.
goto _removeBatchVariablesMyLib

:: ========================================================================
:: LIBRARY FUNCTIONS
:: ========================================================================

:_trimWhitespaceMyLib
REM Trim leading and trailing spaces from a variable.
REM %_argOneMyLib% = name of the variable to trim (passed by name).
if not defined _argOneMyLib goto :eof
setlocal EnableDelayedExpansion
set "_valMyLib=!%_argOneMyLib%!"
REM Trim leading spaces.
for /f "tokens=* delims= " %%a in ("!_valMyLib!") do set "_valMyLib=%%a"
REM Trim trailing spaces.
:_trimTrailingMyLib
if "!_valMyLib:~-1!"==" " (
set "_valMyLib=!_valMyLib:~0,-1!"
goto _trimTrailingMyLib
)
endlocal & set "%_argOneMyLib%=%_valMyLib%"
goto :eof

:_toLowerMyLib
REM Convert a variable's value to lowercase.
REM %_argOneMyLib% = name of the variable to convert (passed by name).
if not defined _argOneMyLib goto :eof
setlocal EnableDelayedExpansion
set "_valMyLib=!%_argOneMyLib%!"
set "_valMyLib=!_valMyLib:A=a!"
set "_valMyLib=!_valMyLib:B=b!"
set "_valMyLib=!_valMyLib:C=c!"
set "_valMyLib=!_valMyLib:D=d!"
set "_valMyLib=!_valMyLib:E=e!"
set "_valMyLib=!_valMyLib:F=f!"
set "_valMyLib=!_valMyLib:G=g!"
set "_valMyLib=!_valMyLib:H=h!"
set "_valMyLib=!_valMyLib:I=i!"
set "_valMyLib=!_valMyLib:J=j!"
set "_valMyLib=!_valMyLib:K=k!"
set "_valMyLib=!_valMyLib:L=l!"
set "_valMyLib=!_valMyLib:M=m!"
set "_valMyLib=!_valMyLib:N=n!"
set "_valMyLib=!_valMyLib:O=o!"
set "_valMyLib=!_valMyLib:P=p!"
set "_valMyLib=!_valMyLib:Q=q!"
set "_valMyLib=!_valMyLib:R=r!"
set "_valMyLib=!_valMyLib:S=s!"
set "_valMyLib=!_valMyLib:T=t!"
set "_valMyLib=!_valMyLib:U=u!"
set "_valMyLib=!_valMyLib:V=v!"
set "_valMyLib=!_valMyLib:W=w!"
set "_valMyLib=!_valMyLib:X=x!"
set "_valMyLib=!_valMyLib:Y=y!"
set "_valMyLib=!_valMyLib:Z=z!"
endlocal & set "%_argOneMyLib%=%_valMyLib%"
goto :eof

:_getTimestampMyLib
REM Write a YYYY-MM-DD_HH-MM-SS timestamp into the named variable.
REM %_argOneMyLib% = name of the output variable.
REM NOTE: Uses %DATE% and %TIME% which are locale-dependent. The parsing
REM below assumes US-style format (e.g., "Fri 04/18/2026" or "04/18/2026").
REM Adjust the substring offsets for your locale, or use PowerShell for
REM a locale-independent alternative:
REM for /f %%a in ('powershell -nop -c "Get-Date -F yyyy-MM-dd_HH-mm-ss"') do set "var=%%a"
if not defined _argOneMyLib goto :eof
setlocal EnableDelayedExpansion
REM Parse date — strip leading day name if present (e.g., "Fri ").
set "_dtMyLib=%DATE%"
if "!_dtMyLib:~3,1!"==" " set "_dtMyLib=!_dtMyLib:~4!"
set "_stampMyLib=!_dtMyLib:~6,4!-!_dtMyLib:~0,2!-!_dtMyLib:~3,2!"
REM Parse time — replace leading space with 0 for single-digit hours.
set "_tmMyLib=%TIME: =0%"
set "_stampMyLib=!_stampMyLib!_!_tmMyLib:~0,2!-!_tmMyLib:~3,2!-!_tmMyLib:~6,2!"
endlocal & set "%_argOneMyLib%=%_stampMyLib%"
goto :eof

:_logMessageMyLib
REM Write a timestamped log line to stdout.
REM %_argOneMyLib% = level (INFO, WARN, ERROR)
REM %_argTwoMyLib% = message text
REM NOTE: Uses %DATE% and %TIME% (locale-dependent). See :_getTimestampMyLib.
setlocal EnableDelayedExpansion
set "_dtMyLib=%DATE%"
if "!_dtMyLib:~3,1!"==" " set "_dtMyLib=!_dtMyLib:~4!"
set "_tmMyLib=%TIME: =0%"
set "_tsMyLib=!_dtMyLib:~6,4!-!_dtMyLib:~0,2!-!_dtMyLib:~3,2! !_tmMyLib:~0,2!:!_tmMyLib:~3,2!:!_tmMyLib:~6,2!"
echo [!_tsMyLib!] [%_argOneMyLib%] %_argTwoMyLib%
endlocal
goto :eof

:_padRightMyLib
REM Pad a string to a given width with trailing spaces.
REM %_argOneMyLib% = the string to pad
REM %_argTwoMyLib% = desired total width
if not defined _argOneMyLib goto :eof
if not defined _argTwoMyLib goto :eof
setlocal EnableDelayedExpansion
set "_valMyLib=%_argOneMyLib%"
set "_padMyLib=%_valMyLib% "
set "_padMyLib=!_padMyLib:~0,%_argTwoMyLib%!"
echo !_padMyLib!
endlocal
goto :eof

:: ========================================================================
:: HELP
:: ========================================================================

:_showHelpMyLib
echo:
for /f "skip=1 delims=" %%a in ('findstr /n "^" "%~f0"') do (
set "_line=%%a"
setlocal EnableDelayedExpansion
for /f "delims=:" %%n in ("!_line!") do set "_lineNum=%%n"
if !_lineNum! GTR %_helpLinesMyLib% (
endlocal
goto :eof
)
set "_text=!_line:*:=!"
if defined _text (
echo !_text:~4!
) else (
echo:
)
endlocal
)
goto :eof

:: ========================================================================
:: CLEANUP — Remove all batch variables.
:: ========================================================================
:_removeBatchVariablesMyLib
set _helpLinesMyLib=
set _funcMyLib=
set _argOneMyLib=
set _argTwoMyLib=
set _argThreeMyLib=
set _valMyLib=
REM Append new variables above this line.
exit /b
Loading
Loading