Skip to content

Instantly share code, notes, and snippets.

@burik666
Created July 24, 2026 17:45
Show Gist options
  • Select an option

  • Save burik666/65c2e8ab502cbdcea18a8510750e71c4 to your computer and use it in GitHub Desktop.

Select an option

Save burik666/65c2e8ab502cbdcea18a8510750e71c4 to your computer and use it in GitHub Desktop.
Quickly create and open temporary Go modules for experimentation.
#!/usr/bin/env bash
# Usage:
# ./go-playground.sh [module-name]
#
# Examples:
# ./go-playground.sh
# ./go-playground.sh my-test
#
# Creates a temporary Go module in $TMPDIR/go-playground/<module-name>
# and opens main.go in the default editor.
set -e
modname="${1:-unnamed}"
ttdir="${TMPDIR:-/tmp}/go-playground/${modname}"
if [[ -e "$ttdir" ]]; then
cd "$ttdir"
else
mkdir -p "$ttdir"
cd "$ttdir"
go mod init "$modname"
fi
"${EDITOR:-vim}" main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment