Windows下PowerShell提示词

chenwei 2026-09-16 23:24 1

终端执行约定



  • 所有终端命令必须在 Windows PowerShell 中执行;调用终端工具时显式指定 PowerShell,不得省略或依赖默认 shell。

  • 默认禁止使用 Bash、WSL、Git Bash 或 cmd。确需使用 cmd 时,必须说明原因,不得跨 shell 拼接命令。

  • 并行执行多条命令时,每条命令分别显式指定 PowerShell。

  • 复杂多行代码使用 PowerShell here-string,并显式调用项目解释器。

  • 禁止使用依赖 Bash/Zsh 的 heredoc、cat <<EOF 等 Unix 专属写法。PowerShell here-string 管道给 python - 可以使用。

  • 需要传递字符串值、路径或正则时使用单引号;PowerShell 单引号内不需要反斜杠转义,连续两个单引号表示一个单引号。

  • 读取文件使用 UTF-8,生成文件使用 UTF-8 No BOM。

最新回复 (8)
  • Eevee 09-16 23:25
    1

    挺需要的,一直写 agents.md ,都有把这个写进去的想法


    但又不咋想到该怎么写

  • chenwei 楼主 09-16 23:26
    2

    如果可以的话最好是配置powershell7,并设置输入输出的编码,有相关教程,并且ps7速度更快,当然如果怕兼容性问题,那么就算了

  • Zennn 09-16 23:27
    3

    1. PowerShell Safety & -LiteralPath



    • Avoid Wildcard Traps: When invoking cmdlets (Get-ChildItem, Remove-Item, Move-Item, Test-Path), ALWAYS use -LiteralPath instead of -Path to prevent errors on paths containing brackets [ or ].

    • Path Quoting: Always wrap paths in single quotes '...'.

    • Trailing Backslash Trap: NEVER put a trailing backslash before a closing quote in native CLI arguments (use 'C:\dir' NOT 'C:\dir\'), otherwise Win32 CommandLineToArgvW escapes the quote (\") and breaks arguments.

    • Directory Verification: Always ensure the destination directory exists before Move-Item -LiteralPath.


    2. Git & File System Specifics (Windows/NTFS)



    • Git Case Renaming: NTFS/ReFS is case-insensitive. To rename file casing (e.g. foo.tsFoo.ts), ALWAYS use two-step moves: git mv foo.ts foo.tmp.ts && git mv foo.tmp.ts Foo.ts.

    • Multiline Git Commits: Write multiline commit messages to a temp file and use git commit -F <file> to prevent Windows quote-stripping issues.

    • CLI Pagers: Ensure pagers do not hang the terminal: prefix with $env:GIT_PAGER = '' or pass --no-pager.


    3. Execution & Toolchain Rules



    • Python / Virtual Envs: Do NOT execute Activate.ps1 (environment states do not persist across stateless tool calls). Directly invoke the target binary: .\venv\Scripts\python.exe or .\venv\Scripts\pip.exe.

    • Non-Interactive Flags: Append -Force, -Confirm:$false, or --yes to commands that might prompt.

    • Interruption Handling: If you are interrupted by the user to ask a question, stop invoking any tools and

      prioritize answering the question directly.


    我是加了这些

  • 林语尘 09-16 23:27
    4

    哎?


    首先谢谢佬的分享ww


    其次我蛮好奇一个问题的


    就是我之前看到的佬大概都是推荐安装一个 Git


    用 Git Bash 这样的命令来进行给 AI 提速的


    现在回过头来用 PowerShell 是因为什么呀?


    不太懂这方面的内容,希望大佬可以给我解惑一下。

  • 李清照 09-16 23:27
    5

    我用Windows的coding的真是太实用了

  • doler 09-16 23:28
    6

    感觉code用pwsh7好像没遇到什么问题。

  • 09-16 23:29
    7

    bash为啥要禁啊

  • 风情 09-17 08:34
    8

    还不错,确实应该禁止使用bash,不然两种方法不一样容易bug

* 帖子来源Linux.do
返回