Reputation: 4681
Can I, with bash bind
, hand a string given by some function to pre-fill a \C-s
query? I was hoping I could do
bind '"\e\C-i": "\C-s$(echo "$FOO")\C-j"'
but that just searches for the exact (unexpanded) $(echo "$FOO")
.
Upvotes: 0
Views: 77
Reputation: 32474
readline
doesn't support evaluating shell expressions in macros, but there is a workaround. Introduce two auxiliary key sequence bindings such that
Your desired key sequence must call 2 followed by 1.
The following is an actual implementation of the above idea, using auxiliary key sequences "\e\C-o"
and "\e\C-p"
(if you are using those for other purposes, don't forget to replace them with unused key sequences):
$ setup_fixedfwdsearchhistory_binding() { bind '"\e\C-o":"\C-s'"$FOO"'\C-j"'; }
$ bind -x '"\e\C-p": setup_fixedfwdsearchhistory_binding'
$ bind '"\e\C-i": "\e\C-p\e\C-o"'
Upvotes: 1