爱意满满的作品展示区。
KasuganoSoras

thefuckplus 命令错误纠正插件

  •  
  •   KasuganoSoras ·
    kasuganosoras · 4h 30m ago · 67 views

    远古命令纠正插件 thefuck 应该很多人都不陌生了,我以前也一直在用,不过它有时候会补错命令,而且部分场景下不太聪明,并且因为它停更很多年了,很多新软件的规则没有更新,所以我就找 Cursor 许愿了一下搞了个 thefuckplus

    和原版 thefuck 走的完全不同的技术路线,thefuckplus 直接接入了 OpenAI 兼容的大模型,利用 AI 结合上下文、退出码、当前路径下的文件来生成正确命令,虽然速度可能不如原版 thefuck (也只是慢个零点几秒,感知不强),但准确得多。而且支持自然语言转命令的功能,有时候一下子想不起来某个命令,可以直接打字生成。

    项目地址: https://github.com/kasuganosoras/thefuckplus

    preview

    功能特性

    输入 / 按键 行为
    fuck 针对上一条命令的执行结果提供修复建议
    fuck <意图> 通过自然语言生成命令,例如:
    fuck 查找大于 100mb 的文件
    ↑ / ↓ 循环切换候选命令,按下方向键时展开完整列表
    Enter 选择命令,保留在缓冲区中(confirm 确认模式)或立即运行(execute 执行模式),可配置
    Tab 始终写入到缓冲区以便手动编辑(即使在 execute 模式下也是如此)
    Esc / Ctrl+C / Ctrl+G 取消选择并退出
    Esc Esc 快速修复上一条命令(可通过 THEFUCKPLUS_ESC_ESC=0 禁用)
    • 文件读取功能: 启用时(默认启用),模型可以调用当前工作目录下的 read_file / list_dir —— 例如,在 npm run build 因实际脚本为 build:h5 而失败后,读取 package.json 文件。
    • 安全性: 候选命令会针对破坏性风险进行评分(模型 + 本地启发式评估)。具有风险的命令会显示警告图标 ⚠。敏感文件(.env、密钥、凭据等)将被默认拦截,除非你主动选择开启。
    • 首次运行: 如果未配置 AI ,系统将自动启动 thefuckplus configure 配置向导。

    快速安装

    git clone https://github.com/kasuganosoras/thefuckplus.git
    cd thefuckplus
    ./scripts/install.sh
    source ~/.zshrc
    thefuckplus configure
    

    oh-my-zsh 用户

    go install github.com/kasuganosoras/thefuckplus/cmd/thefuckplus@latest
    
    git clone https://github.com/kasuganosoras/thefuckplus.git \
      ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/thefuckplus
    

    在 ~/.zshrc 中启用插件:

    plugins=(... thefuckplus)
    

    确保 ~/.local/bin(或你的 GOBIN 路径)已添加到 PATH 环境变量中[cite: 1]。

    手动安装

    git clone https://github.com/kasuganosoras/thefuckplus.git
    cd thefuckplus
    go build -o ~/.local/bin/thefuckplus ./cmd/thefuckplus
    echo 'source ~/path/to/thefuckplus/thefuckplus.plugin.zsh' >> ~/.zshrc
    

    配置说明

    thefuckplus configure
    

    配置文件路径:~/.config/thefuckplus/config.yaml

    provider: openai          # openai | deepseek | custom
    api_key: "sk-..."
    base_url: "https://api.openai.com/v1"
    model: "gpt-4o-mini"
    execute_mode: confirm     # confirm | execute
    max_candidates: 5
    timeout_sec: 30
    agent:
      enabled: true
      max_rounds: 4
      max_file_bytes: 32768
      max_list_entries: 100
      allow_sensitive: false  # 设置为 true 以允许读取 .env / 密钥(仍限制在当前工作目录内)
      extra_allow: []         # 例如 [".env.example"]
      extra_deny: []          # 额外的拒绝匹配规则(优先级最高)
    
    execute_mode 按 Enter 键行为
    confirm(默认) 将命令留在缓冲区中,以便你进行审查/编辑
    execute 立即运行选中的候选命令;Tab 键依然只执行插入缓冲区操作

    也许有人会问,为什么不用 Agent ?这个项目的初衷其实并不是为了替代 Agent ,它只是用来解决日常终端操作时不小心输错命令,或者临时想不起来某个命令的时候用,而不必打开其他软件,就是这么简单的一个功能而已。

    感谢使用,如果有任何问题或者建议可以评论区告诉我~

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3280 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:31 · PVG 21:31 · LAX 06:31 · JFK 09:31
    ♥ Do have faith in what you're doing.