Skip to content

Instantly share code, notes, and snippets.

@backnotprop
Created June 20, 2025 16:00
Show Gist options
  • Save backnotprop/c3a2f153ee6f345995bb5f8e917697ba to your computer and use it in GitHub Desktop.
Save backnotprop/c3a2f153ee6f345995bb5f8e917697ba to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# File: vscode — tiny wrapper around the official `code` CLI
# Usage:
# vscode open <file>
# vscode diff <left> <right> [title]
# vscode cmd <commandId> [jsonArgs]
set -euo pipefail
sub=${1:-}; shift || true
case "$sub" in
open)
[[ $# -eq 1 ]] || { echo "open: need <file>" >&2; exit 1; }
exec code --reuse-window "$1"
;;
diff)
[[ $# -ge 2 ]] || { echo "diff: need <left> <right> [title]" >&2; exit 1; }
left=$1 right=$2 title=${3:-}
exec code --diff "$left" "$right" ${title:+--title "$title"} --reuse-window
;;
cmd)
[[ $# -ge 1 ]] || { echo "cmd: need <commandId> [jsonArgs]" >&2; exit 1; }
cmdId=$1; shift || true
# any remaining arg is passed as JSON string to the command
exec code --command "$cmdId" ${1:+"$1"} --reuse-window
;;
*)
cat <<EOF >&2
usage: vscode {open|diff|cmd} [...]
open <file> – open file in current VS Code window
diff <left> <right> [t] – side-by-side diff
cmd <commandId> [json] – run arbitrary VS Code command
EOF
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment