Enhance your CLI scripts & commands with gum.

r2k0ai
3 min readJan 26, 2024

--

GUM is a command-line tool that provides a set of useful subcommands that you can use to improve the look and functionality of your CLI commands or scripts. Gum can enhance your shell scripts and make them more user-friendly and visually appealing. For a visual demonstration of how gum works, check out this video. I’ll go over some basic commands to help you get started.

How to install

You can install gum with homebrew if you are on macOS or Linux.

brew install gum

Check out this link for other distros.

Basic Commands:

Let’s go over some basic commands.

choose:

You can use gum choose to pick an option from a list of choices.

For example, if you want to choose a Markdown file from a few Markdown files:

$(find . -name "*.md" | gum choose)

Or to choose and open for viewing or editing with an editor:

cat $(find . -name "*.md" | gum choose) 

EDITOR $(find . -name "*.md" | gum choose)

confirm:

You can use gum confirm to confirm an action.

gum confirm "Message" && do something || "Error" //Syntax

For instance, if you want to confirm an action with messages:

gum confirm "Remove file" && rm || "Error"

gum confrim "Do ls" && ls || "No ls for you"

file:

You can use gum file to pick a file from a folder.

For example, if you want to choose and open for viewing or editing with an editor:

Let say if we want to choose and open to view or edit with an editor instead

cat $(gum file .)

EDITOR $(gum file .)

filter:

You can use `gum filter` to filter items from a list.

gum filter

You can combine it with other commands to select a file for a specific action.

cat $(gum filter)

nvim $(gum filter)

Alias

You can further enhance your commands with gum by aliasing them together.

--

--

No responses yet