Skip to content

Instantly share code, notes, and snippets.

@nelhage
Last active January 17, 2025 17:31
Show Gist options
  • Save nelhage/63ff290a7558ed3f89bb3d1cfe358522 to your computer and use it in GitHub Desktop.
Save nelhage/63ff290a7558ed3f89bb3d1cfe358522 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create a temporary file to store the input
tempfile=$(mktemp)
trap 'rm -f "$tempfile"' EXIT
# Read from stdin into the temporary file
cat > "$tempfile"
# Get the preferred editor, defaulting to vim if none is set
editor=${VISUAL:-${EDITOR:-vim}}
# Open the temporary file in the editor
"$editor" "$tempfile" </dev/tty >/dev/tty
# Output the edited content to stdout
cat "$tempfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment