1 # remap_keybindings.bash
2 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
4 # Last modified: 1993-02-03
7 # Conversion to bash v2 syntax done by Chet Ramey
12 #:docstring remap_keybindings:
13 # Usage: remap_keybindings old_function new_function
15 # Clear all readline keybindings associated with OLD_FUNCTION (a Readline
16 # function) rebinding them to NEW_FUNCTION (`self-insert' by default)
18 # This requires bash version 1.10 or newer, since previous versions did not
19 # implement the `bind' builtin.
23 function remap_keybindings
()
25 local unbind_function
="$1"
26 local bind_function
="${2:-'self-insert'}"
30 # If they're the same thing, the work has already been done. :-)
31 if [ "${unbind_function}" = "${bind_function}" ]; then
36 bind_output
="$(bind -q ${unbind_function} 2> /dev/null)"
38 case "${bind_output}" in
39 "${unbind_function} can be invoked via"* ) ;;
40 "" ) return 1 ;; # probably bad argument to bind
41 *) return 0 ;; # unbound
44 # Format of bind_output is like:
45 # 'quoted-insert can be invoked via "\C-q", "\C-v".'
46 # 'self-insert can be invoked via " ", "!", """, "$", "%", ...'
51 # strip off trailing `.' or `,'
57 # bind -q didn't provide whole list of key bindings; jump
58 # to top loop to get more
62 bind "${arg}: ${bind_function}"
69 provide remap_keybindings
71 # remap_keybindings.bash ends here