1

I am using zsh on my Mac and after some bindkey trickery I managed to get left/right/delete/backspace to work on zsh (and bash). In git --interactive, this does not work correctly though.

When I try to commit things in interactive mode, only backspace works. When I press left, right, delete I get the ANSI escape sequences for those keys: ^[[D ^[[C ^[[3~. When I look for these in my bindkey list, they seem to be configured correctly though:

% bindkey | \grep -F "^[[D" 
"^[[D" backward-char
% bindkey | \grep -F "^[[C"
"^[[C" forward-char
% bindkey | \grep -F "^[[3~"
"^[[3~" delete-char

This occurs both when I use bash as well as when I use zsh. It also happens when I use X11's xterm instead of Terminal.app. I have found numerous posts regarding these problems in zsh itself (for example this forum, this post or on SU itself), but none of them relate to git.

In short: left/right/delete keys do work in my shell, but not in git --interactive. How can I fix this?

Tim
  • 1,752

1 Answers1

1

First, special keys are handled by the program itself, not by the tty device. When you press Left, Terminal.app sends ESC [D to bash, and interpreting it is up to bash's Readline library.

The only exceptions are the keys listed in stty -a – when the tty is in "cooked" mode, it itself interprets such keypresses as Backspace. (Bash and Zsh actually use "raw" mode themselves, but switch temporarily to "cooked" before running a program.)

Second, the shells and git --interactive are completely unrelated programs. When you run git, the shell is suspended. All programs get direct access to the tty device, and each uses its own library for interacting with it – bash uses Readline, zsh uses its own ZLE, git --interactive reads from the terminal directly. Bindings made in zsh only apply when zsh, not git, is reading from terminal.

As I said, git --interactive reads from the terminal directly, which means you cannot use Zsh's bindkey or Readline's ~/.inputrc with it. You would have to modify the program to use Readline or a similar library. (Since git-add--interactive is a Perl script, you could rewrite parts of it to use Term::ReadLine, but I don't expect it to be accepted upstream.)

grawity
  • 501,077