3

Asterisk uses the editline library, and the keybindings can be configured in /etc/editrc.

I have defined some of my own keybindins, some other are left to default values.

How can I print the current keybindings in Asterisk? I am looking for something similar to what bindkey does in zsh.

Also, how can I "unbind" a key, such as Ctrl+C ?

And How would I create new keybinding that would bind Ctrl+D to exit/quit ?

here is my current /etc/editrc:

bind "^W" ed-delete-prev-word
bind "\e[1;5D" vi-prev-word
bind "\e[1;5C" vi-next-word
bind ^[[5~ ed-search-next-history
bind ^[[6~ ed-search-prev-history
400 the Cat
  • 819
  • 4
  • 37
  • 85
  • I couldn't find any documentation for /etc/editrc file even in the [Official repo](https://github.com/troglobit/editline) . But [here](https://github.com/troglobit/editline/blob/master/examples/cli.c#L155) is an example of how you can use the API to bind a key. And [here](https://github.com/troglobit/editline/blob/master/src/editline.c#L1942) is the keymap type which contains all of the possible keybindings for libeditline. – Parsa Mousavi May 31 '20 at 14:49
  • Can you please give me an example of the editrc file or any official documentation for it ? I couldn't find anything regarding that in the asterisk docs. – Parsa Mousavi May 31 '20 at 14:55
  • I don't get anything with grepping through both asterisk and editline source code and searching for editrc file. I think in the current situation the best way to answer your question is to send an email directly to some of the [developers](https://github.com/asterisk/asterisk/graphs/contributors) of the project and asking for help. – Parsa Mousavi May 31 '20 at 15:30
  • @Parsa Mousavi - I have edited my question, and added contents of `editrc`. – 400 the Cat May 31 '20 at 15:41
  • @Parsa Mousavi - also, I assume that a solution to bind Ctrl+D might be generic to editrc, not specific to asterisk. That is why asterisk documentation does not mention it. – 400 the Cat May 31 '20 at 15:42
  • The problem is that I cannot find anything useful in the editline docs – Parsa Mousavi May 31 '20 at 16:16

1 Answers1

4

It sounds like it uses NetBSD's editline, a.k.a. libedit.

See the editrc man page

It looks like you can remove bindings using

bind -r ...

Or

bind ... ed-insert

And I guess the easiest thing is to try adding

bind

(without arguments) to the bottom of editrc to list all bindings.

To make Ctrl+D exit, I would try

bind ^d ed-end-of-file

If that doesn't work, you could try making it type "exit" for you using something like

bind -s ^d exit\n

Or you could make Ctrl+D act like Ctrl+C with

bind ^d ed-tty-sigint
Mikel
  • 56,387
  • 13
  • 130
  • 149
  • so how do I bind ctrl+d to quit/exit ? – 400 the Cat May 31 '20 at 16:26
  • Without knowing Asterisk specifics, you could make it type "exit" using something like `bind -s ^d exit\r` – Mikel May 31 '20 at 16:30
  • You could also try `bind ^d ed-end-of-file` – Mikel May 31 '20 at 16:34
  • It looks like the Asterisk bindings are [here](https://github.com/asterisk/asterisk/blob/6b2d9451741cadb080637190af65d40f692d67ed/main/asterisk.c#L3051). It makes Ctrl+D redisplay the screen, basically doing nothing. – Mikel May 31 '20 at 16:45
  • when I add `bind ^d ed-end-of-file` to `/etc/editrc`, then ctrl+d functions same as enter, ie new line. Before I added it, it had no function (nothing happened when I pressed ctrl+d) – 400 the Cat May 31 '20 at 16:53
  • currently, `ctrl+c` basically acts as exit/quit. Is there a way to disable `ctrl+c`, and make `ctrl+d` do what `ctrl+c` used to do ? – 400 the Cat May 31 '20 at 17:00
  • That's unfortunate. Asterisk also doesn't seem to provide libedit with a way to bind to exit natively. Please try the other suggestion to make it type exit then enter – Mikel May 31 '20 at 17:01
  • Interesting. What does `bind` show that Ctrl+C is currently bound to? – Mikel May 31 '20 at 17:03
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/108713/discussion-between-400-the-cat-and-mikel). – 400 the Cat May 31 '20 at 17:03
  • I think it's bound to `ed-tty-sigint`. So you could do `bind ^d ed-tty-sigint` – Mikel May 31 '20 at 17:08
  • that gives me `bind: Invalid command 'ed-tty-sigint'` – 400 the Cat May 31 '20 at 17:09