On Sat, May 13, 2017 at 5:14 PM, L A Walsh <b...@tlinx.org> wrote: > How might one programatically call a bash > function from readline, and pass information from that function > back into readline?
For that, you'd use a combination of `bind -x', READLINE_LINE and READLINE_POINT. For example, if you wanted a key sequence to uppercase the whole rl_line_buffer (READLINE_LINE), then you'd: dualbus@debian:~$ upcase(){ READLINE_LINE=${READLINE_LINE^^}; } dualbus@debian:~$ bind -x '"\C-x\C-u": upcase' dualbus@debian:~$ foo bar baz<Ctrl-x><Ctrl-u> dualbus@debian:~$ FOO BAR BAZ So READLINE_LINE is GNU Readline's `char * rl_line_buffer' <<This is the line gathered so far>> and READLINE_POINT is `int rl_point' <<The offset of the current cursor position in rl_line_buffer (the point)>>. You can do a lot of things with these two alone. I guess you can emulate most of Readline's functions with these three alone. > Also, is it possible to define a readline > function, or only use predefined ones? I have been wondering about that same thing today. i.e. a builtin that allows you to call readline functions from shell functions, e.g. to avoid re-implementing things like `tilde-expand'. > Ex: On a keypress, I would like to be able to > redefine that key in ".bashrc" and have it call a > bash-function that could map the key to itself or > a sequence of keys based on the shell's current state. I don't understand this part.