Friday, April 26, 2024
HomeGolangA Golang-based software for glamorous shell scripts

A Golang-based software for glamorous shell scripts


A software for glamorous shell scripts. Leverage the facility of Bubbles and Lip Gloss in your scripts and aliases with out writing any Golang code!

The above instance is operating from a single shell script (supply).

Tutorial

Gum offers extremely configurable, ready-to-use utilities that can assist you write helpful shell scripts and dotfiles aliases with just some strains of code.

Let’s construct a easy script that can assist you write Standard Commits in your dotfiles.

Begin with a #!/bin/sh.

#!/bin/sh

Ask for the commit sort with gum select:

gum select "repair" "feat" "docs" "type" "refactor" "check" "chore" "revert"

Tip: this command itself will print to stdout which isn’t all that helpful. To utilize the command in a while it can save you the stdout to a $VARIABLE or file.txt.

Immediate for an (optionally available) scope for the commit:

gum enter --placeholder "scope"

Immediate for a commit message:

gum enter --placeholder "Abstract of this variation"

Immediate for an in depth (multi-line) clarification of the adjustments:

gum write --placeholder "Particulars of this variation (CTRL+D to complete)"

Immediate for a affirmation earlier than committing:

gum verify exits with standing 0 if confirmed and standing 1 if cancelled.

gum verify "Commit adjustments?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"

Placing all of it collectively…

#!/bin/sh
TYPE=$(gum select "repair" "feat" "docs" "type" "refactor" "check" "chore" "revert")
SCOPE=$(gum enter --placeholder "scope")

# For the reason that scope is optionally available, wrap it in parentheses if it has a price.
check -n "$SCOPE" && SCOPE="($SCOPE)"

# Pre-populate the enter with the sort(scope): in order that the consumer could change it
SUMMARY=$(gum enter --value "$TYPE$SCOPE: " --placeholder "Abstract of this variation")
DESCRIPTION=$(gum write --placeholder "Particulars of this variation (CTRL+D to complete)")

# Commit these adjustments
gum verify "Commit adjustments?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"

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

Set up

Use a bundle supervisor:

# macOS or Linux
brew set up gum

# Arch Linux (btw)
pacman -S gum

# Nix
nix-env -iA nixpkgs.gum

# Debian/Ubuntu
echo 'deb [trusted=yes] https://repo.appeal.sh/apt/ /' | sudo tee /and so forth/apt/sources.checklist.d/appeal.checklist
sudo apt replace && sudo apt set up gum

# Fedora
echo '[charm]
title=Appeal
baseurl=https://repo.appeal.sh/yum/
enabled=1
gpgcheck=0' | sudo tee /and so forth/yum.repos.d/appeal.repo
sudo yum set up gum

Or obtain it:

  • Packages can be found in Debian and RPM codecs
  • Binaries can be found for Linux, macOS, and Home windows

Or simply set up it with go:

go set up github.com/charmbracelet/[email protected]

Customization

gum is designed to be embedded in scripts and helps all kinds of use circumstances. Parts are configurable and customizable to suit your theme and use case.

You’ll be able to customise with --flags. See gum <command> --help for a full view of every command’s customization and configuration choices.

For instance, let’s use an enter and alter the cursor colour, immediate colour, immediate indicator, placeholder textual content, width, and pre-populate the worth:

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

You may as well use ENVIRONMENT_VARIABLES to customise gum by default, that is helpful to maintain a constant theme for all of your gum instructions.

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

# Makes use of values configured via setting variables above however can nonetheless be
# overridden with flags.
gum enter

Gum input displaying most customization options

Interplay

Enter

Immediate for enter with a easy command.

gum enter > reply.textual content

Immediate for delicate enter with the --password flag.

gum enter --password > password.textual content

Shell running gum input typing Not much, you?

Write

Immediate for some multi-line textual content.

Notice: CTRL+D and esc are used to finish textual content entry. CTRL+C will cancel.

gum write > story.textual content

Shell running gum write typing a story

Filter

Use fuzzy matching to filter an inventory of values:

echo Strawberry >> flavors.textual content
echo Banana >> flavors.textual content
echo Cherry >> flavors.textual content
cat flavors.textual content | gum filter > choice.textual content

Shell running gum filter on different bubble gum flavors

Select

Select an choice from an inventory of selections.

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

You may as well choose a number of gadgets with the --limit flag, which determines the utmost of things that may be chosen.

echo "Decide your prime 5 songs."
cat songs.txt | gum select --limit 5

Or, enable any variety of choices with the --no-limit flag.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments