charmbracelet / gum Goto Github PK
View Code? Open in Web Editor NEWA tool for glamorous shell scripts π
License: MIT License
A tool for glamorous shell scripts π
License: MIT License
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.
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
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
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):
Smartphone (please complete the following information):
would it be possible to add ctrl + j
and ctrl + k
to do the equivalent of what ctrl + n
and ctrl + p
respectively, currently do?
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 choose
don'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:
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:
Before running the filter
command I have a prompt and text in the terminal:
After running the command, everything is replaced with the filter and the previous commands and prompt are lost:
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:
docker:22.04
as the base imageExpected behavior
Should be able of installing gum
using the apt
repo as a source.
Desktop (please complete the following information):
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.
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
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
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
--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!
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
*
*
*
Any help would be appreciated!
Thank you
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:
gum choose --height 4 {{2,A,K,Q,J},{10..3}}" "{β ,β₯,β£,β¦}
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.
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.
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
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.
[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)
π‘ Hi, could you document the recently released (very useful ) --password
option in the README π so people are aware it exists β
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.
eg. mksh, dash, oksh, yash, standard sh, ash, etc etc..
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
:
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.
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!
Similar to [#29] gum confirm should have an option that tells gum whether to default to Yes
(affirmative) or No
(negative).
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, orgum filter
but I cannot select multiple options.$ brew info gum
charmbracelet/tap/gum: stable 0.1.0
$ 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
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.
When using gum spin
the output is suppressed (err and out), could you add an option to allow that output to be returned?
Make an option for the filter command to only show files and folders in the current folder. ie. don't show all contents of all directories within the current directory.
Originally posted by khengyun July 29, 2022
it would be great if it combined with oh-my-posh
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!
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.
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 curl
ing 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.
% brew info gum | head -n 1
charmbracelet/tap/gum: stable 0.1.0
Easiest reproducers:
% ps axuw | gum filter
% ps axuw | gum choose
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.
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
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.
For instance
echo "The quick brown fox" | gum filter
Will show up if I type hioo
in the filter.
I'd prefer an option where it will only show up quick
or k bro
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
\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.
Calling a gum command without doing anything else seems to work exactly as expected.
Attempting to set assign a gum command's stdout to a variable seems to misbehave.
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.
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:
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.
Attempting to redirect a gum command's stdout to a file has apparently identical behavior to assigning it to a variable.
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.
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!
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
Write test
and then hit backspace to delete chars to then select Two Towers.
This is inarticulacy important when we make a typo while writing (happens to me far too much π€£ ).
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.
The result for that is:
W: GPG error: https://repo.charm.sh/apt * InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 03BBF595D4DFD35C
Obviously it works, but you will get a warning on every repo update.
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?
I think it would be great if gum spin
could act as a prettier version of chronic, which hides the output unless an error occurs
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.
Thank you for the great work you do with these terminal libraries, they are awesome!
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).
I am using
is it a problem of my terminal (not to properly obey the colour options) or am I trivially passing the wrong values?
Had a look but can't find a list of all the spinner styles.
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.)
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 resultsI'll try my hand at a PR implementing the above two flags, as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.