Skip to content

Instantly share code, notes, and snippets.

@atdt
Forked from d630/x.sh
Created October 1, 2018 15:16
Show Gist options
  • Save atdt/59c3cf13e0967fc3cefba3b7777f602c to your computer and use it in GitHub Desktop.
Save atdt/59c3cf13e0967fc3cefba3b7777f602c to your computer and use it in GitHub Desktop.
bash: any idea how to use the readline function 'history-and-alias-expand-line' in a recursive way?!
#!/usr/bin/env bash
# Method 1
bind -x '"\C-x4": history_and_alias_expand_line';
bind '"\C-x3": history-and-alias-expand-line';
bind -x '"\C-x2": READLINE_LINE_OLD="$READLINE_LINE"';
bind '"\C-x1": "\C-x2\C-x3\C-x4\C-x5"';
function history_and_alias_expand_line {
if
[[ "$READLINE_LINE" == "$READLINE_LINE_OLD" ]];
then
bind '"\C-x5": abort';
unset -v READLINE_LINE_OLD;
else
bind '"\C-x5": "\C-x1"';
fi;
};
# Method 2
bind '"\C-x2": history-and-alias-expand-line'
bind '"\C-x1": "\C-x(\C-x2\C-x)\M-100\C-xe"'
# vim: set ts=4 sw=4 tw=0 et :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment