V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
youla
V2EX  ›  程序员

我写了一条 powershell 命令,希望 shift+右键打开 powershell 新窗口不要保存历史记录。

  •  
  •   youla · Sep 17, 2020 · 2019 views
    This topic created in 2053 days ago, the information mentioned may be changed or developed.

    现在运行起来,看上去是正常的,但是按↑键往上翻会翻到我的命令里面-Command 传递的参数

    可是我明明已经执行过 [Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()清除历史的命令了。

    在 powershell.exe 里面直接运行没问题,但是放到注册表里就不行了。

    麻烦大家帮我看看哪里错了。

    wt new-tab powershell.exe -NoExit -Command Set-Location -literalPath '%V'|Set-PSReadLineOption -HistorySaveStyle SaveNothing|& {[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()}
    

    虽然会出现一条记录,并不影响使用,但是不完美呀。

    Supplement 1  ·  Sep 19, 2020
    # 已经解决,Powershell新窗口不保存历史记录。
    
    wt new-tab powershell.exe -NoExit -Command Set-Location -literalPath '%V'|powershell.exe -Command Set-PSReadLineOption -HistorySaveStyle SaveNothing|& {[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()}
    
    
    # 如果没有装Windows Terminal,去掉最前面的wt new-tab。
    
    # 应该有人用得着吧~~
    
    Supplement 2  ·  Sep 19, 2020

    发现写错了,当我没来过。。

    Supplement 3  ·  Sep 19, 2020

    这次真的解决了,就这样吧

    wt new-tab powershell.exe -NoExit -Command Set-Location -literalPath '%V'|echo "" > (Get-PSReadlineOption).HistorySavePath
    

    打开powershell时直接把历史记录文件清空了

    不喜欢看到历史记录

    添加到注册表

    计算机\HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command

    6 replies    2020-09-18 14:59:00 +08:00
    youla
        1
    youla  
    OP
       Sep 17, 2020
    我先去洗洗睡,明天早上我必须要看到解决方案,我的程序员们!/doge
    youla
        2
    youla  
    OP
       Sep 18, 2020 via Android
    早上好~
    Lain00
        3
    Lain00  
       Sep 18, 2020 via Android
    这个脚本我看不懂
    我实践中发现 ClearHistory 不能清除历史记录
    Remove-Item (Get-PSReadlineOption).HistorySavePath
    这是我在网上找到的可以清楚历史记录的
    youla
        4
    youla  
    OP
       Sep 18, 2020
    @Lain00 [Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()是清空输入的历史,不是历史记录文件,就是按上键往上翻的那个记录。
    youla
        5
    youla  
    OP
       Sep 18, 2020
    @Lain00 我已经使用了 Set-PSReadLineOption -HistorySaveStyle SaveNothing,是不存储历史记录。
    Lain00
        6
    Lain00  
       Sep 18, 2020 via Android
    我不懂😂
    让会的人来回答吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2435 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 04:08 · PVG 12:08 · LAX 21:08 · JFK 00:08
    ♥ Do have faith in what you're doing.