Giter VIP home page Giter VIP logo

gum's Introduction

Gum

Gum Image

Latest Release Go Docs Build Status

A tool for glamorous shell scripts. Leverage the power of Bubbles and Lip Gloss in your scripts and aliases without writing any Go code!

Shell running the ./demo.sh script

The above example is running from a single shell script (source).

Tutorial

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. Let's build a simple script to help you write Conventional Commits for your dotfiles.

Ask for the commit type with gum choose:

gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert"

Note

This command itself will print to stdout which is not all that useful. To make use of the command later on you can save the stdout to a $VARIABLE or file.txt.

Prompt for the scope of these changes:

gum input --placeholder "scope"

Prompt for the summary and description of changes:

gum input --value "$TYPE$SCOPE: " --placeholder "Summary of this change"
gum write --placeholder "Details of this change"

Confirm before committing:

gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"

Check out the complete example for combining these commands in a single script.

Running the ./examples/commit.sh script to commit to git

Installation

Use a package manager:

# macOS or Linux
brew install gum

# Arch Linux (btw)
pacman -S gum

# Nix
nix-env -iA nixpkgs.gum

# Flox
flox install gum

# Windows (via WinGet or Scoop)
winget install charmbracelet.gum
scoop install charm-gum
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
Fedora/RHEL/OpenSuse
echo '[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=1
gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
sudo rpm --import https://repo.charm.sh/yum/gpg.key

# yum
sudo yum install gum

# zypper
sudo zypper refresh
sudo zypper install gum

Or download it:

  • Packages are available in Debian, RPM, and Alpine formats
  • Binaries are available for Linux, macOS, Windows, FreeBSD, OpenBSD, and NetBSD

Or just install it with go:

go install github.com/charmbracelet/gum@latest

Commands

  • choose: Choose an option from a list of choices
  • confirm: Ask a user to confirm an action
  • file: Pick a file from a folder
  • filter: Filter items from a list
  • format: Format a string using a template
  • input: Prompt for some input
  • join: Join text vertically or horizontally
  • pager: Scroll through a file
  • spin: Display spinner while running a command
  • style: Apply coloring, borders, spacing to text
  • table: Render a table of data
  • write: Prompt for long-form text
  • log: Log messages to output

Customization

You can customize gum options and styles with --flags and $ENVIRONMENT_VARIABLES. See gum <command> --help for a full view of each command's customization and configuration options.

Customize with --flags:

gum input --cursor.foreground "#FF0" \
          --prompt.foreground "#0FF" \
          --placeholder "What's up?" \
          --prompt "* " \
          --width 80 \
          --value "Not much, hby?"

Customize with ENVIRONMENT_VARIABLES:

export GUM_INPUT_CURSOR_FOREGROUND="#FF0"
export GUM_INPUT_PROMPT_FOREGROUND="#0FF"
export GUM_INPUT_PLACEHOLDER="What's up?"
export GUM_INPUT_PROMPT="* "
export GUM_INPUT_WIDTH=80

# --flags can override values set with environment
gum input

Gum input displaying most customization options

Input

Prompt for input with a simple command.

gum input > answer.txt
gum input --password > password.txt

Shell running gum input typing Not much, you?

Write

Prompt for some multi-line text (ctrl+d to complete text entry).

gum write > story.txt

Shell running gum write typing a story

Filter

Filter a list of values with fuzzy matching:

echo Strawberry >> flavors.txt
echo Banana >> flavors.txt
echo Cherry >> flavors.txt
gum filter < flavors.txt > selection.txt

Shell running gum filter on different bubble gum flavors

Select multiple options with the --limit flag or --no-limit flag. Use tab or ctrl+space to select, enter to confirm.

cat flavors.txt | gum filter --limit 2
cat flavors.txt | gum filter --no-limit

Choose

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?"

You can also select multiple items with the --limit or --no-limit flag, which determines the maximum of items that can be chosen.

cat songs.txt | gum choose --limit 5
cat foods.txt | gum choose --no-limit --header "Grocery Shopping"

Shell running gum choose with numbers and gum flavors

Confirm

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"

Shell running gum confirm

File

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

EDITOR $(gum file $HOME)

Shell running gum file

Pager

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

gum pager < README.md

Shell running gum pager

Spin

Display a spinner while running a script or command. The spinner will automatically stop after the given command exits.

To view or pipe the command's output, use the --show-output flag.

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

Shell running gum spin while sleeping for 5 seconds

Available spinner types include: line, dot, minidot, jump, pulse, points, globe, moon, monkey, meter, hamburger.

Table

Select a row from some tabular data.

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

Style

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!'
Bubble Gum, So sweet and so fresh!

Join

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"
I LOVE Bubble Gum written out in four boxes with double borders around them.

Format

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

For more information on template helpers, see the Termenv docs. For a full list of named emojis see the GitHub API.

Running gum format for different types of formats

Log

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."

See the Go time package for acceptable --time formats.

See charmbracelet/log for more usage.

Running gum log with debug and error levels

Examples

How to use gum in your daily workflows:

See the examples directory for more real world use cases.

  • Write a commit message:
git commit -m "$(gum input --width 50 --placeholder "Summary of changes")" \
           -m "$(gum write --width 80 --placeholder "Details of changes")"
  • Open files in your $EDITOR
$EDITOR $(gum filter)
  • Connect to a tmux session
SESSION=$(tmux list-sessions -F \#S | gum filter --placeholder "Pick session...")
tmux switch-client -t $SESSION || tmux attach -t $SESSION
  • Pick a commit hash from git history
git log --oneline | gum filter | cut -d' ' -f1 # | copy
  • Simple skate password selector.
skate list -k | gum filter | xargs skate get
  • Uninstall packages
brew list | gum choose --no-limit | xargs brew uninstall
  • Clean up git branches
git branch | cut -c 3- | gum choose --no-limit | xargs git branch -D
  • Checkout GitHub pull requests with gh
gh pr list | cut -f1,2 | gum choose | cut -f1 | xargs gh pr checkout
  • Copy command from shell history
gum filter < $HISTFILE --height 20
  • sudo replacement
alias please="gum input --password | sudo -nS"

Feedback

We’d love to hear your thoughts on this project. Feel free to drop us a note!

License

MIT


Part of Charm.

The Charm logo

Charmηƒ­ηˆ±εΌ€ζΊ β€’ Charm loves open source

gum's People

Contributors

aa-ko avatar aymanbagabas avatar caarlos0 avatar clysto avatar csandeep avatar deicon avatar dependabot[bot] avatar dhruvmanila avatar enrichman avatar fedeztk avatar gregkh avatar hopefultex avatar keevan avatar kennyp avatar lmarlow avatar maaslalani avatar meowgorithm avatar mikaelfangel avatar mikeoertli avatar muesli avatar muxiu1997 avatar nalze7 avatar nickiel12 avatar nnbnh avatar penguwin avatar piero-vic avatar snan avatar stoux avatar vanielf avatar wissam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gum's Issues

Shell Functions

I'm trying to use bash/shell functions (i.e. function myFunc { doSomething } with gum spin but it's always failing.

Support shell functions as commands in gum spin?

I can't think of any other way to do this besides moving the functions to really long one-liners behind the spin command.

excuse my awful gif quality; ffmpeg is a PITA for gifs
gum_spin

gum choose bug

Describe the bug
Press key up to first selection every page with change to prev page, but the value of select is true.

To Reproduce
Steps to reproduce the behavior:

  1. Input gum choose --height 4 {{2,A,K,Q,J},{10..3}}" "{β™ ,β™₯,♣,♦}
  2. Go to last page
  3. Press key up many times
  4. See error

gum --choose text colours not having effect

Thank you for the great work you do with these terminal libraries, they are awesome!

Problem

gum --chose --selected.foreground

and similar options on colouring of the text items seem to have any effect: see example below (copied and pasted from the docs, where I first use the default command and then I try to enhance it with colour options).

Demo

Screen.Recording.2022-08-01.at.18.20.42.mov

Config

I am using

  • iTerm2 (Version 3.4.16)
  • zsh
  • macOS 12.4.0 Monterey

is it a problem of my terminal (not to properly obey the colour options) or am I trivially passing the wrong values?

When breaking out of choose --no-limit any selections are passed along

While writing up a helper to remove selected branches from git, I discovered that if you break out of a single-item choose list, gum returns nothing, but if you do break out of a multi-item choose, any selected options at the time the ctrl-c was received are returned.

Is this intentional? It was surprising, in that I was expecting to be able to cancel the action by breaking out and it instead proceed with the removal of my test branches.

gum choose <<EOF
Option A
Option B
Option C
EOF

CTRL-C returns nothing

gum choose <<EOF --no-limit
Option A
Option B
Option C
EOF

CTRL-C returns anything you might have selected before breaking.

Windows / PowerShell Functionality

\o I started work last night to make a Chocolatey package for gum since there's a build for Windows. I've been able to get the package sorted out but I started running into problems when I tried writing some example use cases.

Error Examples

Example 1: No Redirection or Assignment

Calling a gum command without doing anything else seems to work exactly as expected.

gum-minimal

Example 2: Variable Assignment

Attempting to set assign a gum command's stdout to a variable seems to misbehave.

gum-var

  1. The prompt is munged with leading whitespace on the second line. I haven't run this down yet but I think this is related to the bubbletea model and some strange interaction when the console tries to go back to regular flow.

  2. The output has an error prepended.

    I expect to see:

    hello!
    

    but instead see (leading whitespace trimmed):

    failed to get console mode for stdout: the handle is invalid.
    hello!
    

    Note:
    I still see this behavior even without my prompt (starting PowerShell with the NoProfile flag). The problem does not appear to be connected to the prompt or to the specific terminal - I see it in the Windows Terminal, the VS Code terminal, and the built-in console host in both PowerShell (versions 5.1 and 7x) and CMD.

    Doing a little digging, this appears to come from containerd/console:

    https://github.com/containerd/console/blob/21ccd90b850f542a0b5a4fee0f5cb2e9b7bd7496/console_windows.go#L54

    It seems this has been a pain point for Windows users of docker compose:

    Though that issue is closed, there are re-reports from this year.

Example 3: Output Redirection

Attempting to redirect a gum command's stdout to a file has apparently identical behavior to assigning it to a variable.

gum-redir

Context

I'm a huge fan of your libraries and tools. I saw gum and immediately thought that it would be great for interactive scripts and would obviate a lot of work to get even an approximately similar UX for folks. I started thinking about a PowerShell module that wraps gum to provide a more familiar (to PowerShell developers) DevX.

If the captured output problem is intractable, I'm happy to write PowerShell handlers to hide away the implementation (strip the error message, etc). What that can't fix (I think) is the prompt munging.

I also noticed that there are completers for other shells and would love to see a completer for PowerShell (and be happy to try my hand at contributing one). I filed this all together as a single issue but if there's a desire to address these Windows-and-PowerShell-specific items, I'm also happy to file separate issues and link to them here as a pseudo-epic.

I'm also happy to help debug/troubleshoot, though my go skills are still nascent.

Filter command clears terminal when run

Describe the bug
Running a standard gum filter command causes my tmux terminal to refresh as if the clear command had been run and I lose my bash prompt. Other gum commands like gum choosedon't seem to have any impact. Is this intentional behavior? Is there a setting or style option that will prevent this from happening? Could a configuration option be added so that you can select from a list without losing everything from before.

To Reproduce
Steps to reproduce the behavior:

  1. Run a gum filter command.

Expected behavior
I would expect for the command to be appended to the terminal rather than for it to clear everything and reset back at the top.

Screenshots
Using choose does not remove any history:
image

Before running the filter command I have a prompt and text in the terminal:
image

After running the command, everything is replaced with the filter and the previous commands and prompt are lost:
image

[bug] gum filter can't use backspace to delete chars

It seems that if you use gum filter doesn't allow for back spaces to delete chars.

Test Case:

echo "The Fellowship of the Ring" >> books.txt
echo "The Two Towers" >> books.txt
echo "The Return of the King" >> books.txt

cat books.txt | gum filter

image

Write test and then hit backspace to delete chars to then select Two Towers.

image

This is inarticulacy important when we make a typo while writing (happens to me far too much 🀣 ).

Can't install by brew

Describe the bug
A clear and concise description of what the bug is.
I can't install by brew

To Reproduce
Steps to reproduce the behavior:
brew install gum

Expected behavior
A clear and concise description of what you expected to happen.
Got a error:

Warning: No available formula or cask with the name "gum". Did you mean gom, gdm, glm or gpm?
==> Searching for similarly named formulae...
These similarly named formulae were found:
gumbo-parser        gom                 gdm                 glm                 gpm
To install one of them, run (for example):
  brew install gumbo-parser
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

Screenshots
If applicable, add screenshots to help explain your problem.
图片

Desktop (please complete the following information):

  • OS: [e.g. iOS] macOS 12.2.1 (21D62)
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] -

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] -
  • OS: [e.g. iOS8.1] -
  • Browser [e.g. stock browser, safari] -
  • Version [e.g. 22] -

Additional context
Add any other context about the problem here.

[Feature Request] Add flag(s?) to `filter` for file and directory filtering

Currently, passing no choices to filter causes it to recursively list every single file, directory, subdirectory, etc. relative to $PWD. This is fantastic, however, in parent directories with many (sometimes hundreds or thousands of) files and subdirectories, this can cause filter to hang, and also produces output which may very well be useless based on the use-case.

In light of this, flags related to filtering contents of the current directory might be useful. Some examples:

  • --list-recursive: Only recurse and show the contents of subdirectories if this flag is passed/true
  • --directories-only: Only show directories in results

I'll try my hand at a PR implementing the above two flags, as well.

the behavior of `--value` is non-obvious

[edit] this was a ticket proposing the addition of a --default option. It turns out that that was user error / ignorance on my part BUT the documentation should still be improved to make it clear what --value does and how it behaves. (see comment below)

:lady_beetle: Minor bug > misalignment issue on gum style with emojis

When playing with the following code :

clear
gum style \
	--foreground 212 --border-foreground 212 --border double \
	--align center --width 50 --margin "1 2" --padding "2 4" \
	'πŸ“¦ Colis-nc πŸ“¦' 'Suivre son colis avec RapidAPI et httpie'

I felt on a minor alignment bug (probably due to emoji) :

image

[Feature] Allow filter with no limits, like `fzf --multi`.

Problem

I am trying to achieve something similar to fzf --multi functionality where I can pipe/filter output from one program through gum for (1) fuzzy-finding and (2) selecting multiple options.

I can accomplish one or the other, like:

  • gum choose --no-limit but I cannot fuzzy search, or
  • gum filter but I cannot select multiple options.

Info

$ brew info gum
charmbracelet/tap/gum: stable 0.1.0

Repro Steps

$ echo -e "abc\ndef\nghi\njkl\nmno\npqr\nstu\nvwx\nyz" | gum choose --no-limit
# cannot type anything
$ echo -e "abc\ndef\nghi\njkl\nmno\npqr\nstu\nvwx\nyz" | gum filter
# cannot select multiple options

Possible Solution

Since gum filter already has fuzzy finding algorithm implemented, so it might be a relatively easier lift to implement multi-selection with something like --no-limit (similar to gum choose) and TAB (not SPACE since it could be part of the search pattern/string) to select the current line and move the pointer to the next line.

[Feature Request] A utility to strip styling

You might remember from my earlier issue, #19, that I am formatting choose options with colors. I discovered that those lines need to be cleaned of their formatting before they can be used elsewhere. This isn't a big deal because I have a workaround using sed.

echo $(echo "$1" | sed 's/\x1b\[[0-9;]*[mGKHF]//g') (thanks StackOverflow)

I just made a function with this so I could call it. But it would be nice to just:

| gum choose --no-limit | gum remove-styling | git add

Hex/Truecolor Coloring

Describe the solution you'd like
A truecolor implementation with hex support.

Additional context
maybe add autodetection of hex versus standard color names, and add rgb/cmyk support if needed.

Consistent escaping of prompt

I've noticed that the way to escape a prompt appears to be different for the different types of prompts. This can be a little non-obvious and confusing.

For example, if I display a write prompt, the ESC key will escape out and continue on.

And then, if I display a choose prompt, the ESC key does nothing, but CTRL-C can circumvent it.

For consistent UX allowing the ESC key to escape prompts may be beneficial.

(P.S. gum is awesome and so handy.)

Add password input

It looks like Bubbles supports having a mask on an input for password entry, but I don't see any implementation of that here. That would be a really useful addition.

[bug]: gum filter empty last line

for instance, when in a directory with several files, running

gum filter

will allow the user to choose one of the files present in the directory, and this would be the expected behavior
however, when piping into gum filter, we get a different behavior

ls | gum filter

will have an empty trailing last line

Add keybinding to choose all options in a `gum choose`

Is your feature request related to a problem? Please describe.
I have a script to update all packages on my mac.

function update_choose() {
  cmds=("brew update && brew upgrade" "brew upgrade --cask --greedy" "npm update -g --fetch-timeout 3000" "yarn global upgrade" "gh extensions upgrade --all" "gup update" "rustup update")
  chose=$(gum choose --no-limit $cmds)
  for cmd in $chose
  do
    eval "$cmd"
  done
}

Describe the solution you'd like

  • I want to be able to easily select everything.
  • If I missed a keybinding, then I want the ability to see what keys do what on each gum command (either in --help or in the rendering itself.

Describe alternatives you've considered
I tried using gum --help to see if I'm missing anything.

Additional context
Awesome tool, love this!

Add Nix

The readme mentions you can install this with nix-env -iA nixpkgs.gum, but there isn't an entry in nixpkgs, including the unstable branch.

Ideally, there would be both a flake and a derivation in nixpkgs.

Allow gum to work correctly with "gum spin $(...)"

Is your feature request related to a problem? Please describe.
Currently "gum spin" is quite limited. For example it doesn't work correctly when used like that:
gum spin VARIABLE=$(...)

Describe the solution you'd like
It should work (should display spinner) when the command is a bit more complicated than simple command [params]

Currently there's no working workaround.

Add --optional flag to `choose` command

Is your feature request related to a problem? Please describe.
Not totally sure if this is a bug or if this should be a feature request. When using the choose --no-limit command it always sends through whichever row is highlighted regardless of whether it has been selected.

Describe the solution you'd like
Add a --optional flag and only return options that are selected (as denoted by an X in the box with default style) when this flag is used. If no options are selected then return an empty string.

Describe alternatives you've considered
The alternative is to bake a blank option into the choices and then add logic to look for result to match this option after gum choose operation.

Additional context

cat ~/choice_example.txt | gum choose --no-limit
> [β€’] one
  [ ] two
  [ ] three
one

Example of it returning whatever the line lands on without explicit selection.

Pressing Ctrl+C in gum filter doesn't exit as expected

Pressing Ctrl + C when in a gum filter dialogue doesn't actually quit anything at the moment, it just exits and continues with whatever line the cursor was on.

I have a short script that, in theory, would allow me to open a terminal, run a command, get a list of all my guitar tabs, select one, open it in my document reader, close the document reader, get the selection dialogue back, and repeat until I press Ctrl + C to quit.

#!/bin/bash
set -e

cd "$HOME/Documents/Music/Guitar" || exit 1

while :; do
    FILE="$(gum filter --placeholder="Choose a song…")" || exit
    devour zathura "$FILE"
done

In practise, the only way to quit is closing the entire terminal because filter doesn't behave as expected when sent SIGINT

[Feature Request] Ability to map `choose` values to keys

This is not a suggested syntax - snippet if purely for demonstration purposes:

gum choose --with-mapping "foo:My foo value" "bar:My bar value"

switch $result
    "foo" -> ...
    "bar" -> ...

Motivation: in many cases it would be nice to use some id-values for choose command instead of duplicating human-readable values two times: in command and in control script.

P.S. Thanks for the tool - it's awesome. Yesterday I integrated in some of my fish functions for administration and it's so much nicer to use now!

Unable to install rpm on Fedora Fedora Silverblue 36

The RPM can not be installed on Fedora Silverblue:

rpm-ostree install gum_0.2.0_linux_amd64.rpm

error: Importing package 'gum': Analyzing /usr/local/share/zsh/site-functions/_gum: Unsupported path; see https://github.com/projectatomic/rpm-ostree/issues/233

[feature] Pass stderr from executed command when running gum spin

Hey everyone!

I am running borg backup via gum spin in a bash script and want to write resulting output from borg to a log file. I noticed that gum seems to pass stdout but swallows stderr.
Borg passes all output through stderr by default as documented here, which makes it difficult to collect logs when running inside of gum spin.

In my opinion it would make sense to introduce a new CLI option called --show-error that can be used like --show-output and passes stderr instead.

Ability to set maximum height for `gum filter`

Is your feature request related to a problem? Please describe.
I have a script to cd into a repo, but when starting to filter, the list is very long and it will be more aesthetic to limit the search results' height.

Describe the solution you'd like
A --height flag or --max-height or something like that.

Describe alternatives you've considered
Non really, using fzf you can do this.

Additional context
Navigating with j/k will go off screen if there are too many results

Easiest way to set up gum to use system colours by default

I've just spun up gum to try out and with a light theme it was not very visible on the terminal.

Now I could pass in the style for the prompt, and then write a utility function to read my system theme (light/dark) and to set prompt colour accordingly, and reuse this utility in each gum prompt.

Is there perhaps a better way to get gum to just use the colours of the shell it is running on?

Introduce a way to have descriptive text before or after `gum write` UI

I would like a way to provide header and/or footer text around the gum write UI. The other input commands let you provide a prompt of some sort. But with gum write, the prompt is repeated for each line, and isn't useful as informative text.

My specific use case is that it isn't obvious that you have to send an EOF (ctrl-D) to indicate when you're done editing the text. So I wanted to have some text either before or after the editing area (maybe using --faint and --italic) to tell people to ctrl-d when done. Other uses could be having some descriptive text that tells them what they're editing.

I could just print it out before calling gum write but then it'll hang around in the terminal history which is ugly. I like how the other prompts like for gum input and gum choose go away.

My current solution is to abuse gum choose with an empty choice as an "interstitial" they have to pass through before being shown gum write:

gum choose --cursor.italic --cursor.faint --cursor="
Press return to edit your script, and ctrl-d to save" ""

Not ideal, as it introduces another step.

Ideally I'd be able to do gum write --intro "Press ctrl-d to save" --intro.faint --intro.italic

(Really don't care what it's called... intro and outro could work. header and footer could work.

[BUG] Gum Choice did not work properly when using with alias

Hi,

I tried to use Gum with kubernetes CLI command and AWK.

The following command is working without alias:

$ kubectl get pod | awk 'NR != 1{split($0,a," "); print a[1]}' | gum choose | xargs -I {} kubectl logs po/{} -f

However when I added this command to alias:

$ alias klogs="kubectl get pod | awk 'NR != 1{split($0,a," "); print a[1]}' | gum choose | xargs -I {} kubectl logs po/{} -f"
$ klogs
*
*
*

See screenshot
Screen Shot 2022-08-02 at 02 36 15

Env:

  1. iTerm 2
  2. ZSH
  3. Go 1.18

Any help would be appreciated!

Thank you

Format independant Choose items

Is there a supported way to apply different style colors to different lines in a choose menu? What I'm looking for is one line to have red text, and another to have blue text. I'm just asking because I couldn't find anything in the documentation about it, did I miss it?

Edit: I am trying to pipe in filenames from another command, and it isn't a static list.

Can't add apt repo on ubuntu 22:04

Describe the bug
Hi guys, i was trying to add gum to an ubuntu:22.04 Dockerfile and have problems adding the repo to the list, so i was wondering if the apt repository is working at all(?).

FROM ubuntu:22.04

RUN apt update
RUN apt install -y software-properties-common

RUN add-apt-repository -y https://repo.charm.sh/apt/
RUN apt update
RUN apt install -y gum

To Reproduce
Steps to reproduce the behavior:

  1. Add the code above inside a Dockerfile that uses docker:22.04 as the base image
  2. Build the image
  3. See 404 not found error

Expected behavior
Should be able of installing gum using the apt repo as a source.

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser: Doesn't apply
  • Version: 22.04

[Feature] Filter allow moving selection up/down with vim keys (i.e. ctrl+j / ctrl+k)

Thanks for this great little bash helper library!

I have a few shell scripts that use fzf to implement a gum filter type of functionality. However, after filtering down to a selection of say 3-4 results, I often then navigate to the one I want with ctrl + vim keys (i.e. ctrl+j (down) or ctrl+k (up)). This seems to be an fzf-only thing.

Gum currenlty only supports using the arrow keys to navigate up/down between items in the filter dialog.

I would love to be able to use ctrl+k / ctrl+j to navigate up/down in the list as well!

Print the output of the command after the spinner is finished

Is your feature request related to a problem? Please describe.
I am currently working on a simple wrapper of curl, and I wanted to return the result of the curling after a spinner, like this:

gum spin --spinner moon --title "Buying Bubble Gum..." -- curl -fsSL curl.se

But gum doesn't return the output of the curl after the spinner exits.

Describe the solution you'd like
I want the spinner to print the output of the command after the command (and the spinner) exits.

Describe alternatives you've considered
I am not aware of any alternatives at the moment. I have also considered using a sleep command instead, then actually do the curl:

gum spin --spinner moon --title "Buying Bubble Gum..." -- sleep 2
curl -fsSL curl.se

But I think this isn't genuine.

Additional context
No additional context.

Add --version parameter

Was just browsing other issues and saw a new release, was curious what version I was on but couldn't determine it from gum itself.

[feature] Preselected entries in gum choose

Hey everyone!

I just encountered a case where I'd want gum choose to display a list of item that are already selected. The user is thus prompted to deselect some of these items while the default behaviour (just pressing Enter) would include all listed items as selected.

This could of course be implemented in the surrounding shell script and by labeling the items something like Disable XY or Omit XY, but this results in bad UX, because you're now dealing with a list of negated items.

I have two proposals right now on how to implement this in gum choose:

Escape characters

Introduce some escape character in the item name that is then parsed and leads to this item being preselected.
This allows for fine-grained control, but is error prone due to additional parsing.

CLI option

Simply add an option like gum choose --selected that simply displays all the given items as preselected.

For example, given the command gum choose --no-limit "foo" "bar" "baz", we expect this output:

> [β€’] foo
  [ ] bar
  [ ] baz

With an additional CLI option, we could turn this into the following output by calling gum choose --preselected --no-limit "foo" "bar" "baz":

> [βœ•] foo
  [βœ•] bar
  [βœ•] baz

I'd love to hear some feedback from the maintainers on this. Thanks in advance for your time!

[feature]: equivalent of fzf --with-nth

let's say, i have for instance the following file.txt:

useful dont_show number one
also_useful idk number two

i would like to filter out some information, and only display a portion of it to the user. with fzf, i could do the following
fzf --with-nth 3.. < file.txt

image

and after i select one of the entries, i get back the whole line with other useful information, which i would not like to be displayed, but would like to use

image

would it be possible for this feature to be implemented, and ideally would it be possible to also integrate regex matching into it, instead of using awk/cut delimiters, like fzf is currently doing? hopefully i was clear enough, sorry if some parts might've sounded confusing

Input placeholder behavior inconsistent with readme

The readme shows the following:
Screen Shot 2022-07-31 at 9 32 45 PM

However, using v0.2.0 the following happens when running the same command:

Screen Shot 2022-07-31 at 9 56 48 PM

Screen Shot 2022-07-31 at 9 56 55 PM

The example appears to suggest the placeholder will be like a prompt on the left, but then that isn't the case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.