如何以编程方式清除iterm2缓冲区?

问题描述 投票:0回答:1

当我使用 iterm2 进行搜索时,使用 ctrl+f,它将搜索缓冲区中较旧的内容,比我在终端中运行的当前进程更旧。在这种情况下,我不关心缓冲区中较旧的内容,我想删除它。

我的问题是 - 有没有办法使用 bash 脚本/命令以编程方式清除缓冲区?当我的进程启动时,我可以调用这个 shell 命令。

iterm2 iterm
1个回答
1
投票

您可以使用AppleScript清除向后滚动缓冲区,然后执行终端

clear
,将以下内容放入bash脚本中(或仅编译AppleScript部分并通过
osascript
运行它)

注意:尝试仅执行“清除缓冲区”将不起作用,因为 cmd 实际上仍在运行并且 iTerm 接受 CMD-K,但它不会清除屏幕...bug?执行时间? ....

#!/bin/bash
read -r -d '' script <<'EOF'
on run argv
   tell application "iTerm"
     tell application "System Events" to keystroke "K" using {shift down, command down}
     tell current window
        tell current session
           write text "clear"
        end tell
     end tell
   end tell
end run
EOF
echo "$script" | osascript ``-'' $@
© www.soinside.com 2019 - 2024. All rights reserved.