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.

7
  • 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. stackoverflow.com/questions/4200800/… Commented May 31, 2015 at 12:39
  • 1
    I guess you want to put this in your .bashrc: bind -x '"\e[1;5A":pipe_send'. Commented May 31, 2015 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... Commented May 31, 2015 at 13:23
  • @cychoi: his "command" is not a keyword. hence the quotes. Commented May 31, 2015 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. Commented May 31, 2015 at 13:32

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.