终端:在stty中映射超级/命令键

我想重新映射终端快捷键(特别是,我想将INTRCTRL+C重新映射为Command+C)在终端中。 所以这些是我的当前的stty绑定。
$ stty -a
speed 38400 baud; 38 rows; 179 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
    -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
    -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
    eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
    min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
    stop = ^S; susp = ^Z; time = 0; werase = ^W;
如果你想要重新映射某些东西,举个例子,就像这样。
stty intr \^c
SIGINT 映射到 CTRL+C 但我希望将 SIGINT 映射到 COMMAND+C。类似于下面这样(不合法):
stty intr ⌘c
现在我知道终端实际上并不识别 Command 键,但有没有一种创造性的方法可以做到呢? 注意:我知道可以使用 ITerm2 来实现,但我想知道是否有办法在原始终端中实现。 谢谢。

嘿,我也想要完全一样的。你找到方法了吗?而且在iTerm 2上如何实现这个呢? - Niklas
@Niklas 我不知道你是否能看到,但我已经更新了帖子,说明了我是如何解决这个问题的。在ITerm2中有一些配置可以交换绑定,但出于个人偏好,我选择了原始的Apple Terminal。 - cozos
我可以,谢谢。不过我更希望找到一个只适用于iTerm 2的解决方案。 - Niklas
2个回答

@Niklas 我解决了这个问题,但没有使用stty。相反,我一直在使用Karabiner-Elements来对终端键进行自定义配置(而不影响其他绑定)。 基本上,你需要安装Karabiner-Elements应用程序,然后在karabiner.json文件中编写一个“复杂修改”规则来交换你想要的内容。这里有一个关于如何配置json配置的指南。 我的karabiner.json大致如下:
{
  "name" : "com.apple.Terminal",
  "simple_modifications" : {
    "left_option" : "left_control",
    "left_command" : "left_option",
    "right_control" : "right_command",
    "right_option" : "right_control",
    "right_command" : "right_option",
    "left_control" : "left_command"
  },
  "complex_modifications" : {
    "rules" : [
      {
        "manipulators" : [
          {
            "to" : [
              {
                "key_code" : "c",
                "modifiers" : [
                  "left_command"
                ]
              }
            ],
            "type" : "basic",
            "from" : {
              "key_code" : "c",
              "modifiers" : {
                "mandatory" : [
                  "left_control"
                ],
                "optional" : [
                  "any"
                ]
              }
           }
        ]
      },
      ... more rules for all the stty characters, etc
    ]
  }
}     

配置文件的名称是否限制这些规则仅适用于终端应用程序,因为我在文档中找不到它。我在哪里可以找到所有已经存在的配置文件? - egelev
1是的,“com.apple.Terminal”限制了键盘只能在该应用程序中进行修改。我也有一个适用于Google Chrome的设置。我也很难找到相关的文档,但在Github上看到有人提到过:https://github.com/tekezo/Karabiner-Elements/issues/808。 - cozos
您可能还会发现以下内容与所提出的解决方案相关:https://genesy.github.io/karabiner-complex-rules-generator - Artfaith

只针对iTerm2用户 您只需要在首选项中添加一个键绑定。首选项 -> 键盘 -> 键绑定。添加一个新的键绑定,选择您的快捷键,并将操作选择为发送十六进制代码。例如,我将⌘Y配置为Ctl-C(中断)。 X03 hex code is for interrupt 点击此链接查找Ascii控制码(控制字符,C0控制)的十六进制代码。