Writing internal operational scripts for deployments, database backups, or onboarding new developers usually results in ugly shell scripts full of awkward read -p "Are you sure? (y/n)" prompts. If you want fuzzy searching or spinners, you historically had to write full programs in Python or Go. gum (by Charmbracelet) brings the power of modern TUI frameworks to plain shell scripts via single, composable CLI commands.
5 Essential `gum` Commands for Shell Scripts
1. Interactive Menus with `gum choose`
ENV=$(gum choose "Development" "Staging" "Production")
echo "Selected environment: $ENV"
2. Fuzzy Autocomplete with `gum filter`
Pipe any list of items into gum filter to let the user search interactively:
BRANCH=$(git branch --format="%(refname:short)" | gum filter)
git checkout "$BRANCH"
3. Beautiful Spinners for Long-Running Tasks
gum spin --spinner dot --title "Compiling release binary..." -- cargo build --release
4. Confirmation Modals
if gum confirm "Are you sure you want to drop the database?"; then
dropdb myapp_db
fi
gum Scripting Composition Model
gum vs Traditional Shell Prompting
| Capability | gum | Standard Bash (`read`) |
|---|---|---|
| Menu Selection | Arrow-key navigation + checkboxes | Type index number manually |
| Fuzzy Filtering | Built-in fuzzy search buffer | Requires manual fzf scripting |
| Password Masking | `gum input --password` | `read -s` (No visual feedback) |
When running gum inside automated CI/CD pipelines or automated cron jobs where no interactive terminal (TTY) is attached, commands like gum choose or gum confirm will fail with a "not a tty" error. Always test whether standard input is interactive (using [ -t 0 ]) before invoking gum in production deployment scripts.
Explore all widgets and styling examples at the official Charm gum repository.
Discussion & Issues
Comments
Post a Comment