【问题标题】:programmatically clear iterm2 buffer以编程方式清除 iterm2 缓冲区
【发布时间】:2018-10-18 20:01:18
【问题描述】:

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

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

【问题讨论】:

    标签: iterm2 iterm


    【解决方案1】:

    您可以使用 AppleScript 清除回滚缓冲区,然后执行终端 clear,将以下内容放入 bash 脚本(或仅编译 AppleScript 部分并通过 osascript 运行)

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

    #!/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 ``-'' $@
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多