I have this snippet in my .inputrc to map jj as enter/return.

 "jj": "\C-M"

It works well but not for commands that are using read, for example entering passwords.

How can I make this to also work on read commands?

  • 4
    read -e enables readline editing on the input. – meuh Sep 24 '18 at 13:19
  • @meuh Thanks for the feedback.. it works, but how about for commands that I dont have control to? like commands that accepts passwords like su? – cevhyruz Sep 24 '18 at 13:34
  • 1
    You cannot make all commands use the readline library. You can prefix some commands with rlwrap which will do readline editing before sending on the line, however your best solution is to use something like tmux in your terminal to handle all input, using its set of bindings. – meuh Sep 24 '18 at 14:11
  • @meuh iguess its really impossible.. can you elaborate more on handling input using tmux? – cevhyruz Sep 25 '18 at 2:42
  • 1
    Since tmux sits between you and the terminal emulator you are using, it can replace anything you type by anything else before passing it on. However, handling your example of "jj" is not really going to be easy to implement in tmux as it is very much oriented to handling only one character at a time, or a special "prefix" character then a single character. Perhaps, if you have some programming experience, you could instead consider using the expect command. It can look at the input for patterns and act on them or pass the data on. Look in its man page for the example for cmd interact. – meuh Sep 25 '18 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.