迷人的shell脚本的工具🎀

作者:Sec-Labs | 发布时间:

167b64ff53102459

 

工具介绍

迷人的Shell脚本的工具。在您的脚本和别名中利用气泡唇彩的力量,而无需编写任何Go代码

db69838a04102542

项目地址

https://github.com/charmbracelet/gum

教程

Gum 提供高度可配置、即用型的实用程序来帮助您编写 只需几行代码即可使用有用的 shell 脚本和点文件别名。

让我们构建一个简单的脚本来帮助您编写 Conventional Commits 为您的 点文件。

从一个开始 #!/bin/sh.

#!/bin/sh

询问提交类型 gum choose:

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

提示:此命令本身将打印到 stdout这并不是那么有用。 要稍后使用该命令,您可以将标准输出保存到 $VARIABLE或者 file.txt.

提示提交的(可选)范围:

gum input --placeholder "scope"

提示提交消息:

gum input --placeholder "Summary of this change"

提示对更改进行详细(多行)说明:

gum write --placeholder "Details of this change"

提交前提示确认:

gum confirm以状态退出 0如果确认和状态 1如果取消。

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

把它们放在一起...

#!/bin/sh
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert")
SCOPE=$(gum input --placeholder "scope")

# Since the scope is optional, wrap it in parentheses if it has a value.
test -n "$SCOPE" && SCOPE="($SCOPE)"

# Pre-populate the input with the type(scope): so that the user may change it
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder "Summary of this change")
DESCRIPTION=$(gum write --placeholder "Details of this change")

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

b5832116f1104341

安装

使用包管理器:

# macOS or Linux
brew install gum

# Arch Linux (btw)
yay -S gum-bin

# Nix
nix-env -iA nixpkgs.gum

# Debian/Ubuntu
echo 'deb [trusted=yes] https://repo.charm.sh/apt/ /' | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install gum

# Fedora
echo '[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=0' | sudo tee /etc/yum.repos.d/charm.repo
sudo yum install gum

或者下载它:

或者只是安装它 go:

go install github.com/charmbracelet/gum@latest

定制

gum旨在嵌入脚本并支持各种使用 案例。 组件是可配置和可定制的,以适应您的主题和 用例。

您可以自定义 --flags. 看 gum <command> --help全面了解 每个命令的自定义和配置选项。

例如,让我们使用一个 input并更改光标颜色,提示颜色, 提示指示器、占位符文本、宽度和预填充值:

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

b5832116f1104607

 

标签:工具分享