LinuxCommandLibrary

gum

Style terminal user interfaces

TLDR

Interactively pick a specific option to print to stdout

$ gum choose ["option1" "option2" "..."]
copy

Open an interactive prompt for the user to input a string with a specific placeholder
$ gum input --placeholder "[value]"
copy

Open an interactive confirmation prompt and exit with either <0> or <1>
$ gum confirm "[Continue?]" --default=false --affirmative "[Yes]" --negative "[No]" [&& echo "Yes selected" || echo "No selected"]
copy

Show a spinner while a command is taking place with text alongside
$ gum spin [[-s|--spinner]] [dot|line|minidot|jump|pulse|points|globe|moon|monkey|meter|hamburger] --title "[loading...]" [command]
copy

Format text to include emojis
$ gum format [[-t|--type]] [emoji] "[:smile: :heart: hello]"
copy

Interactively prompt for multi-line text and write the input to a file
$ gum write > [path/to/file]
copy

SYNOPSIS

gum command [flags]

Examples:
gum input --prompt "What's your name?"
gum choose "apple" "banana" "cherry"
gum confirm "Are you sure?"

PARAMETERS

--width <int>
    Sets the maximum width of the component.

--height <int>
    Sets the maximum height of the component (for list-like components).

--prompt <string>
    Text to display before user input (e.g., for input, confirm).

--placeholder <string>
    Placeholder text for input fields.

--selected <string>
    Initial selected value for choice components.

--header <string>
    Text to display above the component (for list-like components).

--cursor <string>
    Symbol or text to use as a cursor.

--no-limit
    Disables the limit for selectable items in choose or filter.

--help
    Displays help information for the command or subcommand.

--version
    Displays the version of gum.

DESCRIPTION

gum is a modern, open-source command-line tool from Charm designed to enhance shell scripts with interactive Text User Interface (TUI) components. Unlike traditional utilities like read or select, gum provides a rich set of composable utilities for common interactive tasks, such as getting user input, making choices from a list, confirming actions, displaying spinners for long-running processes, formatting text, or rendering markdown. Built on top of the Bubble Tea TUI framework, gum aims to make shell scripts more user-friendly, visually appealing, and robust by abstracting away the complexities of terminal UI programming. It simplifies the creation of engaging command-line experiences without requiring extensive programming knowledge, making it an ideal choice for developers looking to quickly build powerful and interactive CLI tools or automate tasks with a pleasant user interface.

CAVEATS

gum is not a standard, pre-installed utility on most Linux distributions; it must be installed separately. While it significantly enhances shell scripting, its primary focus is on interactive user interfaces rather than core system administration tasks. Terminal compatibility may vary, and advanced customization often requires diving into the specific options of each subcommand.

KEY SUBCOMMANDS

gum operates through a collection of powerful subcommands, each designed for a specific interactive task:

input: Prompts the user for text input.
choose: Allows selection of one or more items from a list.
confirm: Asks for a yes/no confirmation.
filter: Filters input lines using a fuzzy finder.
spin: Displays a spinner while a command runs.
format: Renders markdown, JSON, or other formats.
write: Multi-line text editor for user input.
pager: Displays content in a scrollable view.
style: Applies ANSI styling to text.
log: Displays a structured log viewer.

INSTALLATION

gum can be installed via various package managers or directly from source. Common methods include:

Homebrew (macOS/Linux): brew install gum
Go: go install github.com/charmbracelet/gum@latest
APT (Debian/Ubuntu): sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum

HISTORY

Developed by Charm, the creators of other popular CLI tools like Glow and Bunnyshell, gum was first released to provide modern, interactive UI components for shell scripting. It leverages the Bubble Tea framework for building command-line applications and Glamour for markdown rendering, bringing a polished and aesthetically pleasing experience to the terminal. Its development focuses on ease of use and integrating TUI elements seamlessly into existing shell scripts, addressing the limitations of traditional, less interactive scripting methods.

SEE ALSO

dialog(1), whiptail(1), read(1), select(1), fzf(1)

Copied to clipboard