gpt4 book ai didi

visual-studio-code - vscode终端: terminate process without prompt

转载 作者:行者123 更新时间:2023-12-03 18:31:49 26 4
gpt4 key购买 nike

我习惯于通过按两次 Ctrl+C 来终止 CLI 中的进程,但这在 vscode 的集成终端中不起作用。它提示确认。有没有办法以同样的方式使用它?甚至更好,只需 1 次按键。

最佳答案

看起来提示将在 vscode v1.64 中自动回复。见 Auto-replies in Release notes :

Auto replies

The terminal is now able to automatically reply when a specificsequences of characters is received. A good example of where this isuseful, which is also the only default case, is the Windows batchscript message Terminate batch job (Y/N)? after hitting ctrl+c whenrunning a batch script. This typically just ends up causing problemsfor the user. The terminal will now automatically reply with Y andenter (\r) which makes ctrl+c in Windows feel much better.


terminal auto-reply demo

The feature was made generically so you can setup custom replies forother thing, just be careful when doing this as you are sending textto the process automatically. For example you could use it toautomatically update Oh My Zsh when prompted:

"terminal.integrated.autoReplies": {
"[Oh My Zsh] Would you like to check for updates? [Y/n]": "Y\r"
}

If you use Clink and enable their similar feature, you can disable itin Clink or in VS Code by setting the reply to null to avoid the twofeatures conflicting with each other:

"terminal.integrated.autoReplies": {
"Terminate batch job (Y/N)": null
}
  • 所以看起来你将相应的消息设置为 null禁用 自动回复。

  • set default to null: looks like they are changing the default to disabled.



    没有扩展:
    添加 "workbench.action.terminal.sendSequence"terminal.integrated.commandsToSkipShell通过转到文件 → 首选项 → 设置,然后搜索字符串 terminal.integrated.commandsToSkipShell 在您的 settings.json 中列出,然后单击“在 settings.json 中编辑”。
    如果没有 "terminal.integrated.commandsToSkipShell"在您的 settings.json 中输入,只需添加它:
    ... ,
    "terminal.integrated.commandsToSkipShell": [
    "workbench.action.terminal.sendSequence"
    ]
    然后您还需要添加以下键绑定(bind)(文件 → 首选项 → 键盘快捷键 → 打开 keybindings.json):
    {
    "key": "ctrl+c",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
    "text": "\u0003Y\u000D"
    },
    "when": "terminalFocus && !terminalTextSelected"
    }
    请注意,此解决方案要求您使用 Ctrl-C 两次 ,并且仅适用于 Visual Studio Code 终端。
    这也将改变您在终端中运行的依赖于两个 ctrl-c 指令的任何工具的行为:因为您现在发送大写字母 Y而换行符作为第二条指令,请确保您正在运行的任何东西都有可用的替代退出方式。
    带有扩展名:
    您可以使用 multi-command扩展,通过添加此设置:
    "multiCommand.commands": [
    {
    "command": "multiCommand.terminateTerminal",
    "interval": 1000,
    "sequence": [
    {
    "command": "workbench.action.terminal.sendSequence",
    "args": {
    "text": "\u0003"
    }
    },
    {
    "command": "workbench.action.terminal.sendSequence",
    "args": {
    "text": "Y\u000D"
    }
    },
    ]
    }
    interval在两个 sendSequence 之间提供一个暂停命令,并且两个命令都是必需的:
  • u\003是文本结尾(插入符号 = ^C)。
  • u\000D是一个返回。

  • 然后在 keybindings.json 中添加一个键绑定(bind):
    {
    "key": "ctrl+shift+c",
    "command": "extension.multiCommand.execute",
    "args": { "command": "multiCommand.terminateTerminal" },
    },
    某些组合键将 不是 工作(就像 Ctrl-C 两次的标准序列),但使用 Ctrl-Shift-C,无论光标焦点是在编辑器、文件资源管理器还是终端中,它都能正常工作。
    请注意,这不会杀死或关闭终端或影响其历史记录,它只会在那里停止当前作业。

    关于visual-studio-code - vscode终端: terminate process without prompt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46899480/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com