Windows Batch Snippets

Screenshot
Install
- Dev install: open this folder in VS Code, press
F5 to launch an Extension Development Host, then open a .bat file and try a prefix.
- VSIX: install
vsce (npm i -g @vscode/vsce ), run vsce package , then in VS Code use Extensions: Install from VSIX... .
Marketplace Publishing
- Create or verify a publisher named
smeyilo on the Visual Studio Marketplace (manage publishers at https://marketplace.visualstudio.com/manage).
- Login with
vsce : vsce login smeyilo (follow the instructions to create a PAT with Marketplace scope if prompted).
- Ensure
package.json has "publisher": "smeyilo" , an icon , sensible categories and keywords (already configured).
- Publish:
- First time:
vsce publish 0.2.0
- Next releases:
vsce publish minor (or patch /major )
- Alternatively, create a
.vsix locally with vsce package and upload in the Marketplace UI.
Automated Releases (GitHub Actions)
- Pushing a tag like
v0.2.0 triggers CI to package the VSIX and upload it to the GitHub Release.
- Workflow file:
.github/workflows/release-vsix.yml .
Automated Marketplace Publish
- Workflow:
.github/workflows/publish-marketplace.yml publishes to the Visual Studio Marketplace on tag push.
- One-time setup required:
- Create/verify Publisher
smeyilo at https://marketplace.visualstudio.com/manage
- Generate a VS Marketplace Personal Access Token (PAT) with publish permissions (see
vsce docs)
- Add repo secret
VSCE_PAT (GitHub → Repo → Settings → Secrets and variables → Actions)
- Optional: to publish to Open VSX, add repo secret
OVSX_TOKEN .
- Release flow (local):
git pull --rebase
npm version patch -m "chore: release v%s"
git push origin main --follow-tags
- CI builds the VSIX, creates/updates the GitHub Release, and publishes to Marketplace.
Use Snippets
- Open a
.bat or .cmd file.
- Start typing a prefix (e.g.,
batskel , ifexist , gitac , ghpr ) or press Ctrl+Space to trigger suggestions.
- Confirm a snippet, then press
Tab to move between placeholders.
Included Snippets
batskel — boilerplate with @echo off and setlocal .
bat:usage — usage guard for required arguments.
scriptdir — set SCRIPT_DIR to %~dp0 and pushd into it.
ifexist — file/dir existence check with else.
forfiles — iterate matching files in current folder.
forr — recurse directories and iterate matches.
forf — read a file line-by-line preserving spaces.
forl — numeric loop (for /L ).
sub — subroutine pattern with call :label and goto :eof .
choice — continue/cancel prompt using CHOICE .
berr — run command and check errorlevel .
delayed — EnableDelayedExpansion example.
args — simple argument parsing with SHIFT .
ps — call PowerShell inline.
More Snippets
input — prompt for user input via set /p .
sleep — delay using timeout /t N /nobreak .
robomirror — robust robocopy /MIR with logging and exit codes.
robocopyx — robocopy with excludes (/XD dirs, /XF files).
curlget / dlcert — download via curl or certutil .
7zzip — compress a folder to zip with 7z.exe .
regset / regget — write or read registry values.
elevate — check admin and self‑elevate using PowerShell.
netuse — map a network drive.
logf — append to a log with timestamp subroutine.
stamp — ISO-like timestamp variable for filenames.
start — start a process or open a URL.
kill — kill process by image name (taskkill ).
pathbin — prepend script‑relative bin to PATH .
findstr — recursive text search with line numbers.
forfcsv — parse CSV columns with for /F .
GitHub CLI (gh.exe) Snippets
ghlogin — authenticate to GitHub.
ghstatus — show auth status.
ghcreate — create repo from current folder, set origin , push.
ghclone — clone repo via gh repo clone .
ghfork — fork repo and also clone + set remote.
ghissue / ghissues — create or list issues.
ghpr / ghprco / ghprm — create, checkout, or merge PR.
ghrel / ghrelupload — create release or upload asset.
ghgist — create public gist from file.
ghwflist / ghwfrun — list or trigger workflows.
ghruns / ghrunwatch — list runs or watch a run.
ghsecret — prompt and set repo secret.
ghlabel / ghlabels — create or list labels.
ghapi / ghapipost — REST API call templates (GET/POST).
ghcscreate / ghcslist — create or list Codespaces.
ghcsssh / ghcsstop / ghcsdelete / ghcscode — SSH, stop, delete, or open Codespace in VS Code.
Git Snippets
gitclone — clone a repo to a folder.
gitinit — init repo, first commit, set default branch.
gitst — concise status.
gitac — add and commit.
gitpullr — pull with rebase and autostash.
gitpushu — push and set upstream.
gitnb — create and switch to a new branch.
gitswitch — switch to branch.
gitbd / gitbdr — delete local or remote branch.
gitstash — stash save (incl. untracked) and pop.
gittag — create annotated tag and push.
gitrshard — fetch and hard reset to remote branch.
gitclean — clean untracked files/dirs (dangerous).
gitlg — pretty one-line graph log.
gitamend — amend last commit (no message change).
gitfixup — fixup commit + autosquash rebase.
gitcherry — cherry-pick a commit.
gitroot — set GIT_ROOT and pushd there.
gitwtadd — add a linked worktree for a branch.
gitconf — set global user/email and autocrlf .
Develop / Run
- Open this folder in VS Code and press
F5 to launch an Extension Development Host.
- In the dev host, open a
.bat file and try the prefixes above.
Package (optional)
- Install
vsce once: npm i -g @vscode/vsce .
- From this folder, run:
vsce package to create a .vsix file.
- In VS Code: Command Palette →
Extensions: Install from VSIX... .
Notes
- The language id for Windows Batch is
bat and covers both .bat and .cmd .
- Inside batch files, loop variables use
%% (e.g., %%A ), not %A .
- Some snippets call external tools (
git , gh , 7z , curl ). Ensure they’re installed and on PATH .
- For
gh snippets, authenticate first: run ghlogin or gh auth login .
| |