ShellGPT 接入教程
让你的 Shell 终端变成智能 AI 助手 — 自动生成命令、解释输出、纠错调试
什么是 ShellGPT?
ShellGPT 是一款运行在终端里的 AI 命令助手。它可以:
命令生成
用自然语言描述需求,自动生成 shell 命令
解释输出
看不懂命令输出?让 AI 解释每一行的含义
错误排查
粘贴报错信息,AI 帮你定位和修复问题
适用场景
运维人员、DevOps、Linux 管理员、任何需要在终端工作的场景。
安装 ShellGPT
方式一:Go 安装(推荐)
bash
go install github.com/anthropics/shellgpt@latest
shellgpt --version
方式二:npm 安装
bash
npm install -g @anthropic-ai/shellgpt
shellgpt --version
方式三:pip 安装
bash
pip install shellgpt
shellgpt --version
配置 XiDao Api
ShellGPT 使用 OpenAI 兼容接口:
bash
export OPENAI_API_KEY="sk-你的API_KEY"
export OPENAI_BASE_URL="https://api.xidao.online/v1"
或者创建配置文件 ~/.config/shellgpt/config.yaml:
yaml
openai:
api_key: sk-你的API_KEY
base_url: https://api.xidao.online/v1
使用示例
基本用法
bash
$ shellgpt
How to check if port 8080 is in use
lsof -i :8080
Check docker container status
docker ps -a
What does this kubectl get pods output mean? Explain each column
[paste kubectl get pods output]
Help me write an nginx reverse proxy config
Listen on port 80, forward to localhost:3000
Why is my SSH connection refused?
Check these: 1. Is SSH service running 2. Firewall rules 3. Correct port
管道模式
bash
# Pipe error log to ShellGPT for analysis
cat error.log | shellgpt "Analyze this error and provide solution"
# Format JSON
echo '{"name":"test"}' | shellgpt "Pretty print this JSON"
# Find process
ps aux | grep node | shellgpt "Find the Node process using most memory"
非交互模式(脚本中使用)
bash
# 一次性问答
shellgpt -p "当前目录下最大的文件是什么?"
# 从 stdin 读取输入
echo "解压 tar.gz 文件的命令是什么" | shellgpt -p