windows-safe-grep

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Windows-Safe Grep Skill

Windows安全Grep技能

Problem

问题

On Windows, paths containing backslash-space sequences (e.g.,
D:\Projects\Vibe Code\isometricid
) can cause ripgrep to fail because:
  • The
    \n
    in
    isometricid
    is interpreted as a newline character
  • Combined with the following
    ul
    , this creates a reference to the reserved Windows device name
    nul
  • Error:
    rg: D:\Projects\Vibe Code\isometricid\nul: Incorrect function. (os error 1)
在Windows系统中,包含反斜杠-空格序列的路径(如
D:\Projects\Vibe Code\isometricid
)会导致ripgrep运行失败,原因如下:
  • isometricid
    中的
    \n
    会被解释为换行符
  • 后续的
    ul
    与之结合后,会被识别为Windows系统保留的设备名
    nul
  • 报错信息:
    rg: D:\Projects\Vibe Code\isometricid\nul: Incorrect function. (os error 1)

Solution

解决方案

Use bash commands with proper path quoting to work around this Windows-specific issue:
使用带正确路径引号的Bash命令来规避这个Windows特有的问题:

Safe Grep Command Pattern

安全Grep命令模板

bash
rg --fixed-strings "SEARCH_TERM" "/d/Projects/Vibe Code/isometricid"
Or use forward slashes and proper quoting:
bash
rg --fixed-strings "SEARCH_TERM" "$(cygpath -u "D:\Projects\Vibe Code\isometricid")"
bash
rg --fixed-strings "SEARCH_TERM" "/d/Projects/Vibe Code/isometricid"
或者使用正斜杠并添加正确引号:
bash
rg --fixed-strings "SEARCH_TERM" "$(cygpath -u "D:\Projects\Vibe Code\isometricid")"

Alternative: Use find + grep

替代方案:使用find + grep

bash
find "/d/Projects/Vibe Code/isometricid" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" \) -exec grep -H --line-number "SEARCH_TERM" {} \;
bash
find "/d/Projects/Vibe Code/isometricid" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" \) -exec grep -H --line-number "SEARCH_TERM" {} \;

Usage

使用方法

When grep fails with "Incorrect function (os error 1)" on Windows:
  1. Use this skill
  2. Replace the path with forward slashes:
    D:\Projects\Vibe Code\isometricid
    /d/Projects/Vibe Code/isometricid
  3. Or use the bash command pattern with proper quoting
当在Windows上执行grep出现"Incorrect function (os error 1)"错误时:
  1. 采用本技能提供的方法
  2. 将路径替换为正斜杠格式:
    D:\Projects\Vibe Code\isometricid
    /d/Projects/Vibe Code/isometricid
  3. 或者使用带正确引号的Bash命令模板

Example

示例

bash
rg --fixed-strings "polar_product_id" "/d/Projects/Vibe Code/isometricid/src"
bash
rg --fixed-strings "polar_product_id" "/d/Projects/Vibe Code/isometricid/src"