tom-doerr/zsh_codex

GitHub: tom-doerr/zsh_codex

一款 ZSH 插件,让用户在命令行中通过自然语言注释借助多种 AI 后端自动生成代码和命令补全。

Stars: 1727 | Forks: 97

⌨️ 🦾 Zsh Codex

命令行中的 AI。

Repository's starts Issues License
Latest commit GitHub repository size

You just need to write a comment or variable name and the AI will write the corresponding code.

## 它是什么? 这是一个 ZSH 插件,可让你在命令行中使用 AI 驱动的代码补全功能。它现在同时支持 OpenAI 的 Codex 和 Google 的 Generative AI (Gemini)。OpenAI Codex 也是为 GitHub Copilot 提供支持的 AI,而 Gemini 是 Google 的高级语言模型。 ## 如何安装它? ### 手动安装 1. 安装 OpenAI 包、Google 包或 boto3。 ``` pip3 install openai ``` 或者 ``` pip3 install google-generativeai ``` 或者 ``` pip3 install boto3 ``` 2. 下载 ZSH 插件。 ``` git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex ``` 3. 将以下内容添加到你的 `.zshrc` 文件中。 使用 oh-my-zsh: ``` plugins=(zsh_codex) bindkey '^X' create_completion ``` 不使用 oh-my-zsh: ``` # in your/custom/path you need to have a "plugins" folder and in there you clone the repository as zsh_codex export ZSH_CUSTOM="your/custom/path" source "$ZSH_CUSTOM/plugins/zsh_codex/zsh_codex.plugin.zsh" bindkey '^X' create_completion ``` 4. 在 `~/.config` 中创建一个名为 `zsh_codex.ini` 的文件。 示例: ``` ; Primary service configuration ; Set 'service' to match one of the defined sections below. [service] service = groq_service ; Example configuration for a self-hosted Ollama service. [my_ollama] api_type = openai api_key = dummy_key model = llama3.1 base_url = http://localhost:11434/v1 ; OpenAI service configuration ; Provide the 'api_key' and specify a 'model' if needed. [openai_service] api_type = openai api_key = ; Groq service configuration ; Provide the 'api_key'. [groq_service] api_type = groq api_key = model = gemma2-9b-it ; Mistral service configuration ; Provide the 'api_key'. [mistral_service] api_type = mistral api_key = model = mistral-small-latest ``` 在此配置文件中,你可以定义多个具有各自配置的服务。`api_type` 的必需和可选参数在 `services/sevices.py` 中指定。在 `[service]` 部分选择要使用的服务。 6. 运行 `zsh`,开始输入并使用 `^X` 进行补全! 7. 如果你使用虚拟环境,可以将 `ZSH_CODEX_PYTHON` 设置为安装了 `openai` 或 `google-generativeai` 的 python 可执行文件。 例如,对于 `miniconda`,你可以使用: ``` export ZSH_CODEX_PYTHON="$HOME/miniconda3/bin/python" ``` ### Fig 安装 ## 故障排除 ### 未处理的 ZLE widget 'create_completion' ``` zsh-syntax-highlighting: unhandled ZLE widget 'create_completion' zsh-syntax-highlighting: (This is sometimes caused by doing `bindkey create_completion` without creating the 'create_completion' widget with `zle -N` or `zle -C`.) ``` 在调用 `bindkey` 之前但在加载插件(`plugins=(zsh_codex)`)之后,添加以下行 ``` zle -N create_completion ``` ### 已存在且不是空目录 ``` fatal: destination path '~.oh-my-zsh/custom/plugins' ``` 尝试再次下载 ZSH 插件。 ``` git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex ``` ## 传入上下文 由于当前的文件系统不会传入 AI,你需要: 1. 在你的描述性命令中传入所有上下文 2. 使用命令来收集上下文 要让选项 2 起作用,你需要首先在 .zshrc 文件中添加 `export ZSH_CODEX_PREEXECUTE_COMMENT="true"` 以启用该功能。 完成该操作并重启你的 shell 后,你可以执行如下操作: `# git add all files. Also commit the current changeset with a descriptive message based on $(git diff). Then git push` ## 更多使用示例

[Fish 版本](https://github.com/tom-doerr/codex.fish) [流量统计](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
标签:AI代码补全, AI风险缓解, Petitpotam, SOC Prime, ZSH插件, 人工智能, 开发工具, 效率提升, 用户模式Hook绕过, 逆向工具