5

I want to remap terminal shortcuts (In particular, I want to remap INTR from CTRL+C to Command+C) in Terminal.

So these are my current stty bindings

$ 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;

And for example if you want to remap something it'd be like

stty intr \^c

Which maps SIGINT to CTRL+C

But I want to map SIGINT to COMMAND+C. Something like this (which is invalid):

stty intr ⌘c

Now I know that the terminal doesn't really recognize the Command key, but is there a creative way of doing it?

Note: I know it can be done with ITerm2 but am wondering if there's a way to do it with the vanilla Terminal.

Thanks

  • Hey I also want exactly the same. Did you find a way? Also how is this possible with iTerm 2? – Niklas Mar 13 '18 at 22:15
  • @Niklas I don't know if you can see it but I updated the post with how I solved it. With ITerm2 there are configurations to swap bindings, but I went with the original Apple Terminal because of personal preferences. – cozos Mar 21 '18 at 19:10
  • I can and thank you. I'd prefer to find a solution that works only with iTerm 2 though. – Niklas Mar 21 '18 at 20:24
2

@Niklas I solved the problem, but not using stty. Instead, I've been using Karabiner-Elements to do custom configuration on the Terminal keys (without affecting the rest of my bindings).

Basically you install the Karabiner-Elements app and then write a "complex modifications" rule in the karabiner.json file to swap whatever you want. Here is a guide on how to configure the json config.

My karabiner.json looks something like this:

{
  "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
    ]
  }
}     
  • Is name of the profile restricting these rules to be applied only on the Terminal app because I was not able to find it in the docs. Where can I find all already existing profiles ? – egelev Dec 29 '18 at 11:09
  • 1
    Yes, "com.apple.Terminal" restricts the keys to only be modified in that app. I have one for Google Chrome aswell. I can't find any documentation easily either but see it mentioned on Github: github.com/tekezo/Karabiner-Elements/issues/808. – cozos Dec 30 '18 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .