章节 01
导读 / 主楼:ShellGPT:命令行 AI 生产力工具,让终端拥有 GPT-4 智能
一个基于 GPT-4 等 LLM 的命令行生产力工具,支持生成 Shell 命令、代码片段、文档,并提供聊天模式和 Shell 集成。兼容 Linux、macOS、Windows 及主流 Shell。
正文
一个基于 GPT-4 等 LLM 的命令行生产力工具,支持生成 Shell 命令、代码片段、文档,并提供聊天模式和 Shell 集成。兼容 Linux、macOS、Windows 及主流 Shell。
章节 01
一个基于 GPT-4 等 LLM 的命令行生产力工具,支持生成 Shell 命令、代码片段、文档,并提供聊天模式和 Shell 集成。兼容 Linux、macOS、Windows 及主流 Shell。
章节 02
章节 03
在日常开发工作中,开发者经常需要在终端中执行各种命令——从简单的文件查找到复杂的 Docker 操作。然而,记忆所有命令的语法和参数是一项繁重的认知负担。传统的解决方案是打开浏览器搜索,但这打断了工作流。
ShellGPT 是一个命令行生产力工具,它将 GPT-4 等大语言模型的能力直接带到终端。用户可以用自然语言描述需求,工具自动生成对应的 Shell 命令、代码片段或文档,无需离开终端或查阅外部资源。
章节 04
ShellGPT 最核心的功能是生成并执行 Shell 命令。通过 --shell 或 -s 选项,用户可以用自然语言描述需求:
sgpt --shell "find all json files in current folder"
# -> find . -type f -name "*.json"
# -> [E]xecute, [D]escribe, [A]bort: e
工具会生成命令并提示用户选择:执行(E)、查看说明(D)或取消(A)。这种交互式设计既提供了便利,又保留了用户控制权。
章节 05
ShellGPT 能够识别当前操作系统和使用的 Shell 类型,生成针对性的命令。例如,同样是系统更新请求:
macOS 系统:
sgpt -s "update my system"
# -> sudo softwareupdate -i -a
Ubuntu 系统:
sgpt -s "update my system"
# -> sudo apt update && sudo apt upgrade -y
这种智能适配大大提升了跨平台工作的效率。
章节 06
通过 --code 或 -c 参数,用户可以直接请求生成代码:
sgpt --code "solve fizz buzz problem using python"
生成的代码可以直接重定向到文件:
sgpt --code "solve classic fizz buzz problem using Python" > fizz_buzz.py
python fizz_buzz.py
也可以为已有代码添加注释:
cat fizz_buzz.py | sgpt --code "Generate comments for each line of my code"
章节 07
ShellGPT 支持从 stdin 接收输入,与管道操作无缝集成:
Git 提交信息生成:
git diff | sgpt "Generate git commit message, for my changes"
# -> Added main feature details into README.md
日志分析:
docker logs -n 20 my_app | sgpt "check logs, find errors, provide possible solutions"
文件内容总结:
sgpt "summarise" < document.txt
Here Document 支持:
sgpt << EOF
What is the best way to learn Golang?
Provide simple hello world example.
EOF
章节 08
ShellGPT 支持多轮对话的聊天模式,通过 --chat 选项指定会话名称:
sgpt --chat conversation_1 "please remember my favorite number: 4"
# -> I will remember that your favorite number is 4.
sgpt --chat conversation_1 "what would be my favorite number + 4?"
# -> Your favorite number is 4, so if we add 4 to it, the result would be 8.
聊天会话保存在本地,支持跨命令延续对话上下文。聊天模式可以与 --code 或 --shell 结合使用,实现迭代式代码/命令优化。