Setting the file. One moment.
Executable · Batch Files · github/awesome-copilot · Skills Docs
ContentsBack to the top of the page (opens in a new tab)
assets/ executable.txt
Text · 171 lines · 5 KB
20 ::
21 set "_helpLinesMyTool=19"
22
23 :: ========================================================================
24 :: TEMPLATE INSTRUCTIONS
25 :: 1. Find/Replace "myTool" with your executable name (camelCase).
26 :: 2. Find/Replace "MyTool" with your executable name (PascalCase).
27 :: 3. Update the help block above (lines 2-19) for your tool.
28 :: 4. Implement your logic in :_runMyTool.
29 :: 5. Add any new variables to :_removeBatchVariablesMyTool.
30 :: ========================================================================
31
32 :: Config variables.
33 set "_versionMyTool=1.0.0"
34 set "_verboseMyTool=0"
35
36 :: Define paths.
37 set "_scriptDirMyTool=%~dp0"
38 set "_scriptNameMyTool=%~n0"
39
40 :: Parse arguments into variables.
41 set "_parOneMyTool=%~1"
42 set "_checkParOneMyTool=-%_parOneMyTool%-"
43 set "_parTwoMyTool=%~2"
44 set "_checkParTwoMyTool=-%_parTwoMyTool%-"
45 set "_parThreeMyTool=%~3"
46 set "_checkParThreeMyTool=-%_parThreeMyTool%-"
47
48 :: -----------------------------------------------------------------------
49 :: Handle help and version flags.
50 :: -----------------------------------------------------------------------
51 if "%_parOneMyTool%"=="/?" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
52 if /i "%_parOneMyTool%"=="-h" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
53 if /i "%_parOneMyTool%"=="--help" call :_showHelpMyTool & goto _removeBatchVariablesMyTool
54 if /i "%_parOneMyTool%"=="-v" (
55 echo %_scriptNameMyTool% version %_versionMyTool%
56 goto _removeBatchVariablesMyTool
57 )
58
59 :: -----------------------------------------------------------------------
60 :: Handle --verbose flag (shift arguments if present).
61 :: -----------------------------------------------------------------------
62 if /i "%_parOneMyTool%"=="--verbose" (
63 set "_verboseMyTool=1"
64 set "_parOneMyTool=%~2"
65 set "_checkParOneMyTool=-%~2-"
66 set "_parTwoMyTool=%~3"
67 set "_checkParTwoMyTool=-%~3-"
68 )
69
70 :: Create temp directory for intermediate files.
71 call :_makeTempDirMyTool
72
73 :: -----------------------------------------------------------------------
74 :: Validate required input and start execution.
75 :: -----------------------------------------------------------------------
76 if "%_checkParOneMyTool%"=="--" (
77 echo ERROR: No input specified. Run "%_scriptNameMyTool% /?" for usage. 1>&2
78 goto _removeBatchVariablesMyTool
79 )
80
81 call :_startMyTool
82 goto _removeBatchVariablesMyTool
83
84 :: ========================================================================
85 :: MAIN LOGIC
86 :: ========================================================================
87
88 :_startMyTool
89 if "%_verboseMyTool%"=="1" (
90 echo [VERBOSE] Input: %_parOneMyTool%
91 echo [VERBOSE] Output: %_parTwoMyTool%
92 )
93
94 REM Validate input file exists.
95 if NOT EXIST "%_parOneMyTool%" (
96 echo ERROR: Input file not found: %_parOneMyTool% 1>&2
97 goto :eof
98 )
99
100 call :_runMyTool
101 goto :eof
102
103 :_runMyTool
104 REM ===================================================================
105 REM TODO: Replace this section with your tool's logic.
106 REM ===================================================================
107 echo Processing: %_parOneMyTool%
108
109 if NOT "%_checkParTwoMyTool%"=="--" (
110 echo Output to: %_parTwoMyTool%
111 REM Example: copy input to output.
112 REM copy /Y "%_parOneMyTool%" "%_parTwoMyTool%" >nul
113 )
114
115 echo Done.
116 goto :eof
117
118 :: ========================================================================
119 :: SUPPORT FUNCTIONS
120 :: ========================================================================
121
122 :_showHelpMyTool
123 echo:
124 for /f "skip=1 delims=" %%a in ('findstr /n "^" "%~f0"') do (
125 set "_line=%%a"
126 setlocal EnableDelayedExpansion
127 for /f "delims=:" %%n in ("!_line!") do set "_lineNum=%%n"
128 if !_lineNum! GTR %_helpLinesMyTool% (
129 endlocal
130 goto :eof
131 )
132 set "_text=!_line:*:=!"
133 if defined _text (
134 echo !_text:~4!
135 ) else (
136 echo:
137 )
138 endlocal
139 )
140 goto :eof
141
142 :_makeTempDirMyTool
143 set "_tmpDirMyTool=%TEMP%\%~n0_%RANDOM%%RANDOM%"
144 set "_tmpDirCreatedMyTool=0"
145 if NOT EXIST "%_tmpDirMyTool%" (
146 mkdir "%_tmpDirMyTool%" >nul 2>nul
147 set "_tmpDirCreatedMyTool=1"
148 )
149 goto :eof
150
151 :: ========================================================================
152 :: CLEANUP — Remove all batch variables.
153 :: ========================================================================
154 :_removeBatchVariablesMyTool
155 set _helpLinesMyTool=
156 set _versionMyTool=
157 set _verboseMyTool=
158 set _scriptDirMyTool=
159 set _scriptNameMyTool=
160 set _parOneMyTool=
161 set _checkParOneMyTool=
162 set _parTwoMyTool=
163 set _checkParTwoMyTool=
164 set _parThreeMyTool=
165 set _checkParThreeMyTool=
166 REM Append new variables above this line.
167
168 if "%_tmpDirCreatedMyTool%"=="1" if EXIST "%_tmpDirMyTool%" rmdir /S /Q "%_tmpDirMyTool%" >nul 2>nul
169 set _tmpDirMyTool=
170 set _tmpDirCreatedMyTool=
171 exit /b