2

What I want to do is simple: add a keybinding to one of my program using readline startup file inputrc but, in addition, as my program does not produce any output, I do not want the command name to appear on stdout.

What my problem is:

.inputrc content:

"\e[1;5A":'pipe_send\n'

When I hit ctrl+uparrow, on the command line appears "pipe_send":

[ alexkag@$$$$$:: / ]                                                  
$ pipe_send

What I'd like is not having pipe_send appear on the command line, just like the commands provided by readline such as history-search-backward, history-search-forward, etc. Do you know any way to do that? Maybe shoudn't I use readline? Note: my keybinding must only be visible in bash, not to the whole system.

Jens
  • 69,818
  • 15
  • 125
  • 179
Alexkag
  • 21
  • 2
  • I don't know much about key binding, but since you have already done some research , I believe this link help you in some way. http://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command – mainframer May 31 '15 at 12:39
  • 1
    I guess you want to put this in your `.bashrc`: `bind -x '"\e[1;5A":pipe_send'`. – gniourf_gniourf May 31 '15 at 13:11
  • I don't know anything about readline programming, but keywords such as `history-search-forward` in `.inputrc` are not quoted. I guess they are kind of constants? However, in your example you quote your command (`pipe_send`) as a string which is weird... – cychoi May 31 '15 at 13:23
  • @cychoi: his "command" is not a keyword. hence the quotes. – Karoly Horvath May 31 '15 at 13:29
  • @KarolyHorvath Okay, I got it now. He's not using the readline library to write a program which react to the keybindings. Rather, he's using bash to respond to a key press sequence and then bash will output the string to standard output(?) which hopefully can be fed to his program. – cychoi May 31 '15 at 13:32
  • gniourf_gniourf and mainframer are right : bind -x works for me, thank you guys. – Alexkag May 31 '15 at 13:32
  • `history-search-forward` is a built-in `readline` function, not a literal string. – chepner May 31 '15 at 15:56

1 Answers1

1

As mentioned in the comments by gniourf_gniourf the solution is:

bind -x '"\e[1;5A":pipe_send'

bind -x will tell bash to execute a command whenever a certain key is pressed:

-x keyseq:shell-command

Cause shell-command to be executed whenever keyseq is entered. When shell-command is executed, the shell sets the READLINE_LINE variable to the contents of the Readline line buffer and the READLINE_POINT variable to the current location of the insertion point. If the executed command changes the value of READLINE_LINE or READLINE_POINT, those new values will be reflected in the editing state.

\e[1;5A is the terminal code sent for CtrlUp

Community
  • 1
  • 1
miken32
  • 42,008
  • 16
  • 111
  • 154