用外部命令分割終結者?

用外部命令分割終結者?

我希望能夠從 gnome-pie 或類似的東西向終結者添加框架(而不是選項卡)。 「--help」似乎沒有什麼,但你們有嗎?

答案1

為了模擬任何按鍵組合,我想到的是使用xdotool工具。

安裝$ sudo apt-get install xdotool

用法:

$ xdotool key [key]+[key]

例如

$ xdotool key ctrl+shift+o # To split horizontal
$ xdotool key ctrl+shift+e # To split vertical

有了這個,您可以更輕鬆地創建一些別名。

$ alias splith='xdotool key ctrl+shift+o'
$ alias splitv='xdotool key ctrl+shift+e'

在此輸入影像描述

試一下。

更新

好的,讓我們找到解決方案。

我發現了一個實用程式可以從其他終端執行命令這裡。

建立一個文件$ vim ttyecho.c,複製這段程式碼

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <string.h>
#include <unistd.h>

void print_help(char *prog_name) {
        printf("Usage: %s [-n] DEVNAME COMMAND\n", prog_name);
        printf("Usage: '-n' is an optional argument if you want to push a new line at the end of the text\n");
        printf("Usage: Will require 'sudo' to run if the executable is not setuid root\n");
        exit(1);
    }

int main (int argc, char *argv[]) {
    char *cmd, *nl = "\n";
    int i, fd;
    int devno, commandno, newline;
    int mem_len;
    devno = 1; commandno = 2; newline = 0;
    if (argc < 3) {
        print_help(argv[0]);
    }
    if (argc > 3 && argv[1][0] == '-' && argv[1][1] == 'n') {
        devno = 2; commandno = 3; newline=1;
    } else if (argc > 3 && argv[1][0] == '-' && argv[1][1] != 'n') {
        printf("Invalid Option\n");
        print_help(argv[0]);
    }
    fd = open(argv[devno],O_RDWR);
    if(fd == -1) {
        perror("open DEVICE");
        exit(1);
    }
    mem_len = 0;
    for ( i = commandno; i < argc; i++ ) {
        mem_len += strlen(argv[i]) + 2;
        if ( i > commandno ) {
            cmd = (char *)realloc((void *)cmd, mem_len);
        } else { //i == commandno
            cmd = (char *)malloc(mem_len);
        }

        strcat(cmd, argv[i]);
        strcat(cmd, " ");
    }
    if (newline == 0)
        usleep(225000);
      for (i = 0; cmd[i]; i++)
        ioctl (fd, TIOCSTI, cmd+i);
      if (newline == 1)
        ioctl (fd, TIOCSTI, nl);
    close(fd);
    free((void *)cmd);
    exit (0);
}

然後執行make+文件

$ make ttyecho
$ sudo chown root:root ttyecho
$ sudo cp ttyecho /usr/bin

現在試試看,檢查終結者終端tty

$ tty
/dev/pts/0

在其他終端機執行以下命令

$ ttyecho -n /dev/pts/0 splith

答案2

這是 tachomi 優秀的附錄回答;請按讚。

AFAIK 無法使用(例如)外部 DBUS 指令來分割終止符,因此您需要使用其他答案中建議的按鍵技巧。若要向終結者發送擊鍵,您需要先確保它處於活動狀態。執行此操作的一種方法如下。就我而言,我使用 terminator 作為始終打開的“彈出”終端,使用Ctrl+激活Space。我的腳本檢查它是否隱藏,然後透過模擬Ctrl+使其顯示Space,否則如果它可見,但不在前面,則會啟動視窗。

如果您不將其用作彈出終端,那麼無論如何這都應該可以工作,並且永遠不要執行該條件。

windowlist=$(xprop -root | sed -rn 's/_NET_CLIENT_LIST_STACKING\(WINDOW\): window id # (.*)/\1/p' | tr -d ',')
terminator_visible=false
for i in $windowlist; do
  [[ $(xprop -id $i | grep WM_CLASS\(STRING\)) == 'WM_CLASS(STRING) = "terminator", "Terminator"' ]] && terminator_visible=true && term_id=$i
done

if [[ $terminator_visible == false ]]; then # it's hidden
  xdotool key --clearmodifiers ctrl+space
elif [[ $(xprop -id $(xdotool getactivewindow) | grep WM_CLASS\(STRING\)) != 'WM_CLASS(STRING) = "terminator", "Terminator"' ]]; then # it's visible, but not active
  xdotool windowactivate $term_id 2> /dev/null
fi

運行此腳本來啟動視窗後,只需xdotool按照另一個答案運行命令,即以下之一。我還建議使用--clearmodifiers(請參閱 參考資料man xdotool以獲取更多資訊)。

xdotool key --clearmodifiers ctrl+shift+o
xdotool key --clearmodifiers ctrl+shift+e

答案3

這些天你可以使用remotinator hsplithttps://terminator-gtk3.readthedocs.io/en/latest/advancedusage.html#remotinator

我今天正在尋找這個,只是將其發佈在這裡,以防其他人(或未來的我)也找到這篇文章。

相關內容