tl;dr
1) bind -x '"<some character>":some-function'
; 2) change the READLINE_LINE
/READLINE_POINT
variables in the script
Keybinding
This is a really cool feature that you can use to create/change the behaviour of keys in your terminal.
Before we proceed
Keep in mind that you can set the keybindings in your ~/.inputrc
or ~/.bashrc
(or any other file that is sourced on start).
Here we have two examples of setting the arrou up
to get the previous command that matches the initial text written so far (kind of Ctrl+r
). Just note that history-search-backward
is a builtin function.
Here is a simple example using a custom function
The READLINE_LINE
and READLINE_POINT
variables
Those variables just store the current text and the cursor position. Here is a simple example of dealing with them:
Here you can see another example of dealing with binding keys and updating the input text, where I start fzf and update the text based on the user’s action.
Comments