gum

Gum provides highly configurable, ready-to-use utilities to help you write useful shell scripts and dotfiles aliases with just a few lines of code.

Gum

Usage

Example:

#!/bin/sh
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert")
SCOPE=$(gum input --placeholder "scope")
 
# Since the scope is optional, wrap it in parentheses if it has a value.
test -n "$SCOPE" && SCOPE="($SCOPE)"
 
# Pre-populate the input with the type(scope): so that the user may change it
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder "Summary of this change")
DESCRIPTION=$(gum write --placeholder "Details of this change (CTRL+D to finish)")
 
# Commit these changes
gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"

gum choose

Choose an option from a list of choices Usage: gum choose [<options> ...]

OptionEnvironment VariableDescription
--ordered$GUM_CHOOSE_ORDEREDMaintain the order of the selected options
--height=10$GUM_CHOOSE_HEIGHTHeight of the list
--cursor="> "$GUM_CHOOSE_CURSORPrefix to show on item that corresponds to the cursor position
--header=""$GUM_CHOOSE_HEADERHeader value
--cursor-prefix="○ "$GUM_CHOOSE_CURSOR_PREFIXPrefix to show on the cursor item (hidden if limit is 1)
--selected-prefix="◉ "$GUM_CHOOSE_SELECTED_PREFIXPrefix to show on selected items (hidden if limit is 1)
--unselected-prefix="○ "$GUM_CHOOSE_UNSELECTED_PREFIXPrefix to show on unselected items (hidden if limit is 1)
--selected=,...$GUM_CHOOSE_SELECTEDOptions that should start as selected
--timeout=0$GUM_CCHOOSE_TIMEOUTTimeout until choose returns selected element
--limit=1-Maximum number of options to pick
--no-limit-Pick unlimited number of options (ignores limit)
--select-if-one-Select the given option if there is only one
--cursor.foreground="212"$GUM_CHOOSE_CURSOR_FOREGROUNDForeground Color
--header.foreground="240"$GUM_CHOOSE_HEADER_FOREGROUNDForeground Color
--item.foreground=""$GUM_CHOOSE_ITEM_FOREGROUNDForeground Color
--selected.foreground="212"$GUM_CHOOSE_SELECTED_FOREGROUNDForeground Color

Example: Choose an option from a list of choices.

echo "Pick a card, any card..."
CARD=$(gum choose --height 15 {{A,K,Q,J},{10..2}}" "{♠,♥,♣,♦})
echo "Was your card the $CARD?"

gum confirm

Ask a user to confirm an action Usage: gum confirm [<prompt>]

OptionEnvironment VariableDescription
--default-Default confirmation action
--affirmative="Yes"-The title of the affirmative action
--negative="No"-The title of the negative action
--timeout=0$GUM_CONFIRM_TIMEOUTTimeout until confirm returns selected value or default if provided
--prompt.foreground=""$GUM_CONFIRM_PROMPT_FOREGROUNDForeground Color
--selected.foreground="230"$GUM_CONFIRM_SELECTED_FOREGROUNDForeground Color
--unselected.foreground="254"$GUM_CONFIRM_UNSELECTED_FOREGROUNDForeground Color

Example: Confirm whether to perform an action. Exits with code 0 (affirmative) or 1 (negative) depending on selection.

gum confirm && rm file.txt || echo "File not removed"

gum file

Pick a file from a folder Usage: gum file [<path>]

OptionEnvironment VariableDescription
[<path>]$GUM_FILE_PATHThe path to the folder to begin traversing
-c, --cursor=">"$GUM_FILE_CURSORThe cursor character
-a, --all$GUM_FILE_ALLShow hidden and ‘dot’ files
--file$GUM_FILE_FILEAllow files selection
--directory$GUM_FILE_DIRECTORYAllow directories selection
--height=0$GUM_FILE_HEIGHTMaximum number of files to display
--timeout=0$GUM_FILE_TIMEOUTTimeout until command aborts without a selection
--cursor.foreground="212"$GUM_FILE_CURSOR_FOREGROUNDForeground Color
--symlink.foreground="36"$GUM_FILE_SYMLINK_FOREGROUNDForeground Color
--directory.foreground="99"$GUM_FILE_DIRECTORY_FOREGROUNDForeground Color
--file.foreground="" $GUM_FILE_FILE_FOREGROUNDForeground Color
--permissions.foreground="244"$GUM_FILE_PERMISSIONS_FOREGROUNDForeground Color
--selected.foreground="212"$GUM_FILE_SELECTED_FOREGROUNDForeground Color
--file-size.foreground="240"$GUM_FILE_FILE_SIZE_FOREGROUNDForeground Color

Example: Prompt the user to select a file from the file tree.

EDITOR $(gum file $HOME)

gum filter

Filter items from a list Usage: gum filter [<options> ...]

OptionEnvironment VariableDescription
--indicator="•$GUM_FILTER_INDICATORCharacter for selection
--selected-prefix=" ◉ "$GUM_FILTER_SELECTED_PREFIXCharacter to indicate selected items (hidden if limit is 1)
--unselected-prefix=" ○ "$GUM_FILTER_UNSELECTED_PREFIXCharacter to indicate unselected items (hidden if limit is 1)
--header=""$GUM_FILTER_HEADERHeader value
--placeholder="Filter..."$GUM_FILTER_PLACEHOLDERPlaceholder value
--prompt="> "$GUM_FILTER_PROMPTPrompt to display
--width=20$GUM_FILTER_WIDTHInput width
--height=0$GUM_FILTER_HEIGHTInput height
--value=""$GUM_FILTER_VALUEInitial filter value
--reverse$GUM_FILTER_REVERSEDisplay from the bottom of the screen
--[no-]fuzzy$GUM_FILTER_FUZZYEnable fuzzy matching
--[no-]sort$GUM_FILTER_SORTSort the results
--timeout=0$GUM_FILTER_TIMEOUTTimeout until filter command aborts
--indicator.foreground="212"$GUM_FILTER_INDICATOR_FOREGROUNDForeground Color
--selected-indicator.foreground="212"$GUM_FILTER_SELECTED_PREFIX_FOREGROUNDForeground Color
--unselected-prefix.foreground="240"$GUM_FILTER_UNSELECTED_PREFIX_FOREGROUNDForeground Color
--header.foreground="240"$GUM_FILTER_HEADER_FOREGROUNDForeground Color
--text.foreground=""$GUM_FILTER_TEXT_FOREGROUNDForeground Color
--cursor-text.foreground=""$GUM_FILTER_CURSOR_TEXT_FOREGROUNDForeground Color
--match.foreground="212"$GUM_FILTER_MATCH_FOREGROUNDForeground Color
--prompt.foreground="240"$GUM_FILTER_PROMPT_FOREGROUNDForeground Color
--limit=1-Maximum number of options to pick
--no-limit-Pick unlimited number of options (ignores limit)
--select-if-one-Select the given option if there is only one
--[no-]strict-Only returns if anything matched. Otherwise return Filter

Example: Use fuzzy matching to filter a list of values:

echo Strawberry >> flavors.txt
echo Banana >> flavors.txt
echo Cherry >> flavors.txt
cat flavors.txt | gum filter > selection.txt

gum format

Format a string using a template Usage: gum format [<template> ...]

OptionEnvironment VariableDescription
[<template> ...]-Template string to format (can also be provided via stdin)
--theme="pink"$GUM_FORMAT_THEMEGlamour theme to use for markdown formatting
-l, --language="" $GUM_FORMAT_LANGUAGEProgramming language to parse code
-t, --type="markdown"$GUM_FORMAT_TYPEFormat to use (markdown, template, code, emoji)

Example: format processes and formats bodies of text. gum format can parse markdown, template strings, and named emojis.

# Format some markdown
gum format -- "# Gum Formats" "- Markdown" "- Code" "- Template" "- Emoji"
echo "# Gum Formats\n- Markdown\n- Code\n- Template\n- Emoji" | gum format
 
# Syntax highlight some code
cat main.go | gum format -t code
 
# Render text any way you want with templates
echo '{{ Bold "Tasty" }} {{ Italic "Bubble" }} {{ Color "99" "0" " Gum " }}' \
    | gum format -t template
 
# Display your favorite emojis!
echo 'I :heart: Bubble Gum :candy:' | gum format -t emoji

gum input

Prompt for some input Usage: gum input

OptionEnvironment VariableDescription
--placeholder="Type something..."$GUM_INPUT_PLACEHOLDERPlaceholder value
--prompt="> "$GUM_INPUT_PROMPTPrompt to display
--cursor.mode="blink"$GUM_INPUT_CURSOR_MODECursor mode
--value=""-Initial value (can also be passed via stdin)
--char-limit=400-Maximum value length (0 for no limit)
--width=40$GUM_INPUT_WIDTHInput width (0 for terminal width)
--password-Mask input characters
--header=""$GUM_INPUT_HEADERHeader value
--timeout=0$GUM_INPUT_TIMEOUTTimeout until input aborts
--prompt.foreground=""$GUM_INPUT_PROMPT_FOREGROUNDForeground Color
--cursor.foreground="212"$GUM_INPUT_CURSOR_FOREGROUNDForeground Color
--header.foreground="240"$GUM_INPUT_HEADER_FOREGROUNDForeground Color

Example: Prompt for input with a simple command.

gum input > answer.txt

Prompt for sensitive input with the —password flag.

gum input --password > password.txt

gum join

Join text vertically or horizontally Usage: gum join <text> ...

OptionDescription
--align="left"Text alignment
--horizontalJoin (potentially multi-line) strings horizontally
--verticalJoin (potentially multi-line) strings vertically

Example: Combine text vertically or horizontally. Use this command with gum style to build layouts and pretty output.

Tip: Always wrap the output of gum style in quotes to preserve newlines (\n) when using it as an argument in the join command.

I=$(gum style --padding "1 5" --border double --border-foreground 212 "I")
LOVE=$(gum style --padding "1 4" --border double --border-foreground 57 "LOVE")
BUBBLE=$(gum style --padding "1 8" --border double --border-foreground 255 "Bubble")
GUM=$(gum style --padding "1 5" --border double --border-foreground 240 "Gum")
 
I_LOVE=$(gum join "$I" "$LOVE")
BUBBLE_GUM=$(gum join "$BUBBLE" "$GUM")
gum join --align center --vertical "$I_LOVE" "$BUBBLE_GUM"

gum pager

Scroll through a file Usage: gum pager [<content>]

OptionEnvironment VariableDescription
--show-line-numbers-Show line numbers
--soft-wrap-Soft wrap lines
--timeout=0$GUM_PAGER_TIMEOUTTimeout until command exits
--foreground=""$GUM_PAGER_FOREGROUNDForeground Color
--help.foreground="241"$GUM_PAGER_HELP_FOREGROUNDForeground Color
--line-number.foreground="237"$GUM_PAGER_LINE_NUMBER_FOREGROUNDForeground Color
--match.foreground="212"$GUM_PAGER_MATCH_FOREGROUNDForeground Color
--match-highlight.foreground="235"$GUM_PAGER_MATCH_HIGH_FOREGROUNDForeground Color

Example: Scroll through a long document with line numbers and a fully customizable viewport.

gum pager < README.md

gum spin

Display spinner while running a command Usage: gum spin <command> ...

OptionEnvironment VariableDescription
--show-output$GUM_SPIN_SHOW_OUTPUTShow or pipe output of command during execution
-s, --spinner="dot"$GUM_SPIN_SPINNERSpinner type. Available spinner types include: line, dot, minidot, jump, pulse, points, globe, moon, monkey, meter, hamburger.
--title="Loading..."$GUM_SPIN_TITLEText to display to user while spinning
-a, --align="left"$GUM_SPIN_ALIGNAlignment of spinner with regard to the title
--timeout=0$GUM_SPIN_TIMEOUTTimeout until spin command aborts
--spinner.foreground="212"$GUM_SPIN_SPINNER_FOREGROUNDForeground Color
--title.foreground=""$GUM_SPIN_TITLE_FOREGROUNDForeground Color

Example: To view or pipe the command’s output, use the --show-output flag.

gum spin --spinner dot --title "Buying Bubble Gum..." -- sleep 5

gum style

Apply coloring, borders, spacing to text Usage: gum style [<text> ...]

OptionEnvironment VariableDescription
--foreground=""$FOREGROUNDForeground Color
--background=""$BACKGROUNDBackground Color
--border="none"$BORDERBorder Style
--border-background=""$BORDER_BACKGROUNDBorder Background Color
--border-foreground=""$BORDER_FOREGROUNDBorder Foreground Color
--align="left"$ALIGNText Alignment
--height=0$HEIGHTText height
--width=0$WIDTHText width
--margin="0 0"$MARGINText margin
--padding="0 0"$PADDINGText padding
--bold$BOLDBold text
--faint$FAINTFaint text
--italic$ITALICItalicize text
--strikethrough$STRIKETHROUGHStrikethrough text
--underline$UNDERLINEUnderline text

Example: Pretty print any string with any layout with one command.

gum style \
	--foreground 212 --border-foreground 212 --border double \
	--align center --width 50 --margin "1 2" --padding "2 4" \
	'Bubble Gum (1¢)' 'So sweet and so fresh!'

gum table

Render a table of data Usage: gum table

OptionEnvironment VariableDescription
-s, --separator=","-Row separator
-c, --columns=COLUMNS,...-Column names
-w, --widths=WIDTHS,...-Column widths
--height=10-Table height
-p, --print-static print
-f, --file=""-file path
-b, --border="rounded"-border style
--border.foreground=""$GUM_TABLE_BORDER_FOREGROUNDForeground Color
--cell.foreground=""$GUM_TABLE_CELL_FOREGROUNDForeground Color
--header.foreground=""$GUM_TABLE_HEADER_FOREGROUNDForeground Color
--selected.foreground="212"$GUM_TABLE_SELECTED_FOREGROUNDForeground Color

Example: Select a row from some tabular data.

gum table < flavors.csv | cut -d ',' -f 1

gum write

Prompt for long-form text Usage: gum write

OptionEnvironment VariableDescription
--width=50$GUM_WRITE_WIDTHText area width (0 for terminal width)
--height=5$GUM_WRITE_HEIGHTText area height
--header=""$GUM_WRITE_HEADERHeader value
--placeholder="Write something..."$GUM_WRITE_PLACEHOLDERPlaceholder value
--prompt="┃ "$GUM_WRITE_PROMPTPrompt to display
--show-cursor-line$GUM_WRITE_SHOW_CURSOR_LINEShow cursor line
--show-line-numbers$GUM_WRITE_SHOW_LINE_NUMBERSShow line numbers
--value=""$GUM_WRITE_VALUEInitial value (can be passed via stdin)
--char-limit=400-Maximum value length (0 for no limit)
--cursor.mode="blink"$GUM_WRITE_CURSOR_MODECursor mode
--base.foreground=""$GUM_WRITE_BASE_FOREGROUNDForeground Color
--cursor-line-number.foreground="7"$GUM_WRITE_CURSOR_LINE_NUMBER_FOREGROUNDForeground Color
--cursor-line.foreground=""$GUM_WRITE_CURSOR_LINE_FOREGROUNDForeground Color
--cursor.foreground="212"$GUM_WRITE_CURSOR_FOREGROUNDForeground Color
--end-of-buffer.foreground="0"$GUM_WRITE_END_OF_BUFFER_FOREGROUNDForeground Color
--line-number.foreground="7"$GUM_WRITE_LINE_NUMBER_FOREGROUNDForeground Color
--header.foreground="240"$GUM_WRITE_HEADER_FOREGROUNDForeground Color
--placeholder.foreground="240"$GUM_WRITE_PLACEHOLDER_FOREGROUNDForeground Color
--prompt.foreground="7"$GUM_WRITE_PROMPT_FOREGROUNDForeground Color

Example:

Note: CTRL+D is used to complete text entry. CTRL+C and esc will cancel.

gum write > story.txt

gum log

Log messages to output Usage: gum log <text> ...

OptionEnvironment VariableDescription
-o, --file=STRING-Log to file
-f, --format-Format message using printf
--formatter="text"-The log formatter to use
-l, --level="none"-The log level to use
--prefix=STRING-Prefix to print before the message
-s, --structured-Use structured logging
-t, --time=""-The time format to use (kitchen, layout, ansic, rfc822, etc…)
--level.foreground=""$GUM_LOG_LEVEL_FOREGROUNDForeground Color
--time.foreground=""$GUM_LOG_TIME_FOREGROUNDForeground Color
--prefix.foreground=""$GUM_LOG_PREFIX_FOREGROUNDForeground Color
--message.foreground=""$GUM_LOG_MESSAGE_FOREGROUNDForeground Color
--key.foreground=""$GUM_LOG_KEY_FOREGROUNDForeground Color
--value.foreground=""$GUM_LOG_VALUE_FOREGROUNDForeground Color
--separator.foreground=""$GUM_LOG_SEPARATOR_FOREGROUNDForeground Color

Example: log logs messages to the terminal at using different levels and styling using the charmbracelet/log library.

# Log some debug information.
gum log --structured --level debug "Creating file..." name file.txt
# DEBUG Unable to create file. name=temp.txt
 
# Log some error.
gum log --structured --level error "Unable to create file." name file.txt
# ERROR Unable to create file. name=temp.txt
 
# Include a timestamp.
gum log --time rfc822 --level error "Unable to create file."

Examples

Connect to a TMUX session

Pick from a running tmux session and attach to it. Or, if you’re already in a tmux session, switch sessions.

SESSION=$(tmux list-sessions -F \#S | gum filter --placeholder "Pick session...")
tmux switch-client -t $SESSION || tmux attach -t $SESSION

Pick commit hash from your Git history

Filter through your git history searching for commit messages, copying the commit hash of the commit you select.

git log --oneline | gum filter | cut -d' ' -f1 # | copy

Choose packages to uninstall

List all packages installed by your package manager (we’ll use brew) and choose which packages to uninstall.

brew list | gum choose --no-limit | xargs brew uninstall

Choose branches to delete

List all branches and choose which branches to delete.

git branch | cut -c 3- | gum choose --no-limit | xargs git branch -D