| name | charm-gum |
| description | Interactive shell script prompts, fuzzy filters, spinners, and styled output with gum. Use when building bash/shell script UIs, gum commands, interactive shell prompts, or CLI script workflows. NOT for Go terminal forms (use huh). |
charm-gum
gum is a CLI for glamorous shell scripts. All interaction writes to stdout; capture with $(). All commands render to stderr so stdout stays clean for piping.
Quick Start
brew install gum
go install github.com/charmbracelet/gum@latest
NAME=$(gum input --placeholder "your name")
gum confirm "Continue?" && echo "hello $NAME"
Every flag has an env var equivalent: --placeholder = GUM_INPUT_PLACEHOLDER. Export env vars to set defaults project-wide.
Command Reference
input - single-line prompt
gum input [flags]
NAME=$(gum input --placeholder "full name" --header "Enter your name")
PASS=$(gum input --password --placeholder "password")
write - multi-line textarea
gum write [flags]
BODY=$(gum write --placeholder "PR description..." --header "Description" --width 80)
choose - pick from a list
gum choose [options...] [flags]
TYPE=$(gum choose "fix" "feat" "docs" "chore" "refactor")
PKGS=$(brew list | gum choose --no-limit --header "Remove packages")
filter - fuzzy search a list
gum filter [options...] [flags]
SESSION=$(tmux list-sessions -F '#S' | gum filter --placeholder "pick session...")
BRANCH=$(git branch | cut -c 3- | gum filter --placeholder "checkout...")
confirm - yes/no prompt
gum confirm [prompt] [flags]
gum confirm "Delete branch?" && git branch -D "$BRANCH"
gum confirm "Overwrite?" --affirmative "Overwrite" --negative "Skip" || exit 0
spin - spinner while command runs
gum spin [flags] -- <command>
gum spin --title "Installing deps..." -- npm install
OUTPUT=$(gum spin --show-output --title "Fetching..." -- curl -s https://api.example.com/data)
style - styled text output
gum style [flags] "text" ["text2" ...]
gum style --foreground 212 --border rounded --padding "1 2" "Done!"
format - render markdown, code, templates, emoji
gum format [flags] [text...]
echo "# Hello\n- item 1\n- item 2" | gum format
cat script.sh | gum format -t code -l bash
echo '{{ Bold "OK" }} {{ Color "99" "0" " gum " }}' | gum format -t template
echo "I :heart: gum :candy:" | gum format -t emoji
join - compose styled blocks side by side or stacked
gum join [flags] "block1" "block2"
A=$(gum style --border rounded --padding "0 2" "left")
B=$(gum style --border rounded --padding "0 2" "right")
gum join "$A" "$B"
file - file picker from tree
gum file [path]
$EDITOR "$(gum file $HOME)"
pager - scrollable viewer
gum pager < README.md
gum pager --show-line-numbers < file.txt
table - pick a row from CSV
gum table < data.csv
gum table -c Name,Age,Role < users.csv | cut -d',' -f1
log - structured log output
gum log --level info "Server started" port 8080
gum log --structured --level error "Failed" file foo.txt
gum log --time rfc822 --level warn "Slow response"
Shell Script Patterns
1. conventional commit helper
#!/bin/bash
set -e
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore")
SCOPE=$(gum input --placeholder "scope (optional)")
[ -n "$SCOPE" ] && SCOPE="($SCOPE)"
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder "short summary")
BODY=$(gum write --placeholder "longer description (ctrl+d to skip)" --height 6)
gum confirm "Commit?" || exit 0
git commit -m "$SUMMARY" ${BODY:+-m "$BODY"}
2. interactive branch cleanup
#!/bin/bash
set -e
BRANCHES=$(git branch | cut -c 3- | gum choose --no-limit --header "Branches to delete")
[ -z "$BRANCHES" ] && exit 0
gum style --foreground 196 --bold "Will delete:"
echo "$BRANCHES" | gum format
gum confirm "Delete these branches?" --affirmative "Delete" --negative "Cancel" || exit 0
echo "$BRANCHES" | while IFS= read -r branch; do
gum spin --title "Deleting $branch..." -- git branch -D "$branch"
gum log --level info "Deleted" branch "$branch"
done
3. deploy script with env selection
#!/bin/bash
set -e
ENV=$(gum choose "staging" "production" --header "Deploy target")
TAG=$(git tag --sort=-v:refname | gum filter --placeholder "pick version tag...")
gum style \
--border rounded --border-foreground 214 \
--padding "1 3" --margin "1" \
"Deploy $TAG to $ENV?"
gum confirm "Proceed?" --default=false || exit 0
gum spin --title "Deploying $TAG to $ENV..." --show-error -- \
./deploy.sh "$ENV" "$TAG"
gum style --foreground 82 --bold "Deployed $TAG to $ENV"
4. quick file notes launcher
#!/bin/bash
VAULT="$HOME/notes"
FILE=$(find "$VAULT" -name "*.md" | sed "s|$VAULT/||" \
| gum filter --placeholder "search notes..." --height 20)
[ -z "$FILE" ] && exit 0
$EDITOR "$VAULT/$FILE"
5. package manager TUI
#!/bin/bash
set -e
ACTION=$(gum choose "install" "remove" "update" --header "Package action")
case "$ACTION" in
install)
PKG=$(gum input --placeholder "package name")
gum spin --title "Installing $PKG..." -- brew install "$PKG"
;;
remove)
PKGS=$(brew list | gum choose --no-limit --header "Select packages to remove")
[ -z "$PKGS" ] && exit 0
gum confirm "Remove selected?" || exit 0
echo "$PKGS" | xargs gum spin --title "Removing..." -- brew uninstall
;;
update)
gum spin --title "Updating Homebrew..." --show-error -- brew update
gum spin --title "Upgrading packages..." --show-output -- brew upgrade
;;
esac
gum log --level info "Done" action "$ACTION"
Styling
Colors accept ANSI 256 codes (212) or hex (#FF79C6). Padding/margin use CSS shorthand: "1 2" = top/bottom 1, left/right 2.
banner() {
gum style \
--foreground 212 --border-foreground 212 \
--border double --align center \
--padding "1 4" --margin "1 2" \
"$@"
}
banner "Build Complete" "v1.4.2"
LEFT=$(gum style --border rounded --padding "0 3" --foreground 82 "OK")
RIGHT=$(gum style --border rounded --padding "0 3" --foreground 196 "ERR")
gum join "$LEFT" "$RIGHT"
Style env vars use GUM_<CMD>_<FLAG> format. Set in shell profile for persistent defaults:
export GUM_CHOOSE_CURSOR_FOREGROUND="#FF79C6"
export GUM_INPUT_PLACEHOLDER="..."
export GUM_SPIN_SPINNER="dot"
Common Mistakes
- capturing output: gum writes the prompt to stderr, result to stdout.
VAL=$(gum input) works correctly.
- spin command separator:
-- is required before the command: gum spin --title "..." -- npm install. Without it gum parses your command as its own flags.
- confirm exit code:
gum confirm returns 0 for yes, 1 for no. Use &&/|| not if [ $? -eq 0 ] - both work but && is idiomatic.
- join with newlines: always quote
$(gum style ...) in join args or newlines collapse: gum join "$A" "$B" not gum join $A $B.
- filter with no match: by default
--strict is on - filter returns nothing if no match. Use --no-strict to return the query string instead.
- choose vs filter:
choose = static list, cursor navigation. filter = fuzzy search while typing. Use filter for long lists.
- multi-select output: each selection on its own line. Iterate with
while IFS= read -r item; do ... done <<< "$SELECTION".
Checklist