1 个不稳定版本
0.1.0 | 2024年6月4日 |
---|
#1009 在 开发工具
36KB
682 行
Shelldon
Shelldon 是一个用 Rust 编写的命令行工具。它提供了一套用于执行 shell 命令、管理提示符和与 OpenAI GPT 交互的实用程序。
是的,又一个具有 GPT 功能的 CLI。Shelldon 并不打算成为终端中的完整 GPT 客户端;对于这一点,有一些 CLI 要好得多,还有很多应用程序,甚至 OpenAI ChatGPT 应用程序。Shelldon 的目的是解决一些个人用例,对我来说非常有用;我希望它也能对您有所帮助。此外,我还制作它是为了好玩地玩 Rust!
[!重要] 对于我的用例来说,其他工具缺失的功能之一是能够使用自定义提示符来执行特定的任务。因此,我创建了 Shelldon,使其能够管理提示符并在需要时使用它们。您可以在此处了解更多关于此功能的信息 这里。我还计划通过插件扩展它以集成更复杂的流程。
安装
Shelldon 提供了预构建的二进制文件的 GitHub 发布,适用于 MacOS 和 Linux。
Homebrew
brew tap douglasmakey/tap
brew install shelldon
从源代码构建
如果您想从源代码构建 Shelldon,您可以克隆仓库并使用 cargo 构建
git clone https://github.com/douglasmakey/shelldon.git
cd shelldon
cargo build --release
使用
要使用 Shelldon,您需要设置您的 OpenAI 令牌。您可以通过设置环境变量来完成此操作。以下是如何在您的终端中设置它的方法
export OPENAI_API_KEY="your-openai-api-key"
Shelldon 允许您轻松地将 GPT 功能集成到您的 shell 命令中。以下是一些示例以帮助您入门
运行 Shell 命令
$ shelldon "Show all the graphics ports for the Vagrant machine using Libvirt."
Command to execute: vagrant ssh -c "virsh list --all | grep vagrant | awk '{print \$1}' | xargs -I {} virsh domdisplay {}"
? [R]un, [M]odify, [C]opy, [A]bort ›
分析 Docker 日志
使用 Shelldon 分析 Docker 日志并识别错误
$ docker logs nginx | shelldon "check logs, find errors"
调试 Kubernetes
Shelldon 可帮助您了解 Kubernetes pod 失败的原因
$ k describe pod nginx | shelldon ask "why this pod is failing?"
The pod is failing because it was terminated due to an "Out of Memory" (OOM) condition. The `OOMKilled` reason indicates that the container running in the pod exceeded its memory limit, causing the system to kill the process to prevent it from affecting other processes on the node.
Here are some steps you can take to address this issue:
...
在 GPT 的帮助下生成配置文件
$ shelldon "Create a basic nginx configuration file"
Configuration file content:
server {
listen 80;
server_name example.com;
location / {
proxy_pass https://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
...
轻松自动化常规系统任务
$ shelldon exec "Find and delete all log files older than 30 days in /var/log"
Command to execute: find /var/log -name "*.log" -type f -mtime +30 -exec rm {} \;
? [R]un, [M]odify, [C]opy, [A]bort ›
获取编写有意义的 Git 提交信息的帮助
$ git diff | shelldon "Generate a commit message" --copy
"Refactor logging system to improve error handling and performance. This change updates the logging library and adjusts the log levels for better clarity."
您可以使用 --copy
命令直接将输出复制到您的剪贴板。
处理提示符
Shelldon 允许您创建、编辑、列出和删除自定义提示,以简化您的命令行工作流程。以下是您如何管理您的提示:
命令概述
$ shelldon prompts -h
Usage: shelldon prompts <COMMAND>
Commands:
create Create a new prompt
edit Edit an existing prompt
list List all prompts
delete Delete an existing prompt
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
列出提示
要查看您创建的所有提示,请使用列表命令
$ shelldon prompts list
╭────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────╮
│ Name ┆ Content ┆ Variables │
╞════════════╪═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╪═══════════╡
│ script ┆ Let’s think step by step and act as a {script:bash} code scripts expert. Provide only the {script} script code as output without any descriptions or explanations. Ensure the output is in plain text format without Markdown formatting or symbols. If ┆ script │
│ ┆ details are insufficient, provide the most logical solution. You are not allowed to ask for more details. Just print the script directly. ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
│ translator ┆ Let’s think step by step and act as a translator. Translate the following text from {from:english} to {to:spanish}. Make it sound natural to a native speaker of {to} while keeping the original tone. Do only minimal edits without changing the tone. ┆ from, to │
│ ┆ Avoid using fancy words. Reply with only the translated text and nothing else. Do not provide explanations. ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
│ note-taker ┆ I am software engineer and I’d like you to look at the following text I wrote and edit it to make it sound more natural to a native English speaker. Do only minimal/minor edits without changing the tone of the text, which should remain the same. ┆ │
│ ┆ Dont use fancy words and I want you to only reply the correction, the improvements and nothing else, do not write explanations. ┆ │
╰────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────╯
您可以使用 {}
语法将变量添加到提示中,并可以使用 --set key=value
选项来覆盖这些值。此外,在提示模板中,您可以定义默认值,如 {from:spanish}
。这允许您根据用户输入自定义灵活和动态的提示。
然后,您可以使用定义的模板运行 ask 命令
在我的日常工作中,我经常需要生成 bash 和 python 脚本或 cloud-init 文件。 shelldon
帮助我完成这项任务
shelldon ask --prompt script "Generate a cloud-init script to set up an Ubuntu server with the following steps:
1. Update Ubuntu.
2. Install Nginx.
3. Create a custom HTML file to be served by Nginx.
4. Ensure Nginx is enabled and started." --set script=cloud-init > cloud-init
如您所见,我们可以直接将输出重定向到文件以创建脚本。
或者一些翻译。
alias sat="shelldon ask --prompt translator"
sat "Hey guys, I'm a few minutes late for the meeting, in less than 5 minutes I'll be there."
Hola chicos, voy unos minutos tarde para la reunión, en menos de 5 minutos estaré ahí.
您还可以修改模板的值
alias sat="shelldon ask --prompt translator"
sat "Chicos voy a llegar 5 minutos tarde a la reunion" --set to=english --set from=spanish
Guys, I'm going to be 5 minutes late to the meeting.
因此,能够处理带有参数的动态提示并使用它们,使 Shelldon 成为我有用的工具。
TODO
- 实现打印输出的最佳方式。
- 添加测试。
- 改进错误处理。
- 添加默认提示。
- 实现 OpenAI 功能?
- 实现 Ollama?也许在将来。你需要它吗?
贡献
欢迎贡献、建议和讨论!无论您是增强功能、完善概念还是修复错误,您的输入都是宝贵的。
依赖关系
~13–26MB
~387K SLoC