Skip to content

Instantly share code, notes, and snippets.

@taikedz
Last active January 8, 2026 15:34
Show Gist options
  • Select an option

  • Save taikedz/3cc4158b8afc58b5a6add2cd0dbf9d58 to your computer and use it in GitHub Desktop.

Select an option

Save taikedz/3cc4158b8afc58b5a6add2cd0dbf9d58 to your computer and use it in GitHub Desktop.
Create new files

Create new things

Quick scriptlets to create new little assets for various scripting and experimentation

#!/usr/bin/env bash
mkdir -p "$1"
echo "*" >> "$1/.gitignore"
#!/usr/bin/env bash
set -euo pipefail
git init "$1"
cd "$1"
git checkout -b main
populate() {
if [ ! -e "$1" ]; then
echo -e "$2" > "$1"
fi
}
populate README.md "# $(basename "$PWD")"
populate LICENSE.txt "All rights reserved - for now."
populate .gitignore "*.swp\n*.pyc\n*.venv\nbin/"
#!/usr/bin/env bash
fail() { echo "$*"; exit 1; }
progname="${1:-}"; shift || fail "Specify program binary name"
modname="${1:-}" ; shift || fail "Specify mod name"
cat <<EOF >> "$progname.go"
package main
import (
"$modname/lib"
)
func main() {
$progname.Hello()
}
EOF
mkdir -p lib
cat <<EOF >> "lib/$progname.go"
package $progname
import (
"fmt"
)
func Hello() {
fmt.Printf("Hello, $progname\n")
}
EOF
cat <<EOF >> build.sh
#!/usr/bin/env bash
HERE="$(dirname "$0")"
cd "$HERE"
# Create a full-static binary that should not require dependencies on libc
# https://stackoverflow.com/questions/61319677/flags-needed-to-create-static-binaries-in-golang
CGO_ENABLED=0 go build -trimpath -o bin/$progname -a -ldflags '-extldflags -static' "$progname.go"
EOF
chmod 755 build.sh
(set -x
go mod init "$modname"
)
#!/usr/bin/env bash
# Create a helpful python script stub
cat <<'EOTEMP'
#!/usr/bin/env python3
import os
import pathlib
import argparse
THIS = pathlib.Path(os.path.realpath(__file__))
HEREDIR = pathlib.Path(os.path.dirname(THIS))
def cli_args():
# further quick examples at https://dev.to/taikedz/ive-parked-my-side-projects-3o62
parser = argparse.ArgumentParser()
#parser.add_argument("terms", help="Positional terms (one or more)", nargs="+") # for zero or more, use 'nargs="*"'
#parser.add_argument("--option", "-o", help="An option with a string value")
#parser.add_argument("--option", "-o", action="store_true", help="An option with a boolean value, default false") # use store_false for opposite default
#parser.add_argument("--number", "-n", type=int, default=0, help="An option with a numeric value") # type can be any function returning a value
args = parser.parse_args()
# optionally validate now
assert args.number < 5, "Maximum of 4"
return args
def main():
args = cli_args()
# do the rest here
# Generic launch and catch assertions
if __name__ == "__main__":
try:
main()
except Exception as e:
# Catches all exceptions, but not KeyboardInterrupt
# Normally silence tracebacks. Run with PY_TRACEBACK=true to show them
if os.getenv("PY_TRACEBACK") == "true":
raise
else:
print(e)
exit(1)
EOTEMP
#!/usr/bin/env bash
cat <<'EOTEMP'
#!/usr/bin/env bash
THIS="$(realpath "$0")"
HEREDIR="$(dirname "$THIS")"
SCRIPT="$(basename "$0")"
set -euo pipefail
main() {
}
main "$@"
EOTEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment