Skip to content

Instantly share code, notes, and snippets.

@d630
Last active May 10, 2017 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d630/fcb48ccb2940b2818ced1883cf0d4dc8 to your computer and use it in GitHub Desktop.
Save d630/fcb48ccb2940b2818ced1883cf0d4dc8 to your computer and use it in GitHub Desktop.
bash
#/usr/bin/env bash
function bar {
[[ -n $READLINE_LINE ]] || return 0;
eval "
function f {
$READLINE_LINE
};
" 2> /dev/null || { bind '"\C-x3": edit-and-execute-command' && i=1; };
};
function foo {
((i)) && bind '"\C-x3": accept-line' && i=0;
};
bind '"\C-x3": accept-line';
bind -x '"\C-x2": foo;bar';
bind '"\C-x1": "\C-x2\C-x3"';
#!/usr/bin/env bash
function lich {
READLINE_LINE=$(
function p { printf '%s\n' "$READLINE_LINE"; };
n='\!';
nn=/tmp/bash.$$.hn.${n@P};
\p > "$nn";
vim -f \
"+set ft=sh" "+call cursor(1,$READLINE_POINT+1)" "$nn" </dev/tty >/dev/tty;
if
cmp -s <(\p) "$nn";
then
\p;
return 1;
else
cat "$nn";
fi;
);
};
function bar {
until
[[ -n $READLINE_LINE ]] || return 0;
eval "
function f {
$READLINE_LINE
};
" 2> /dev/null
do
lich || { i=1; bind '"\C-x3": abort'; break; }
done;
};
function foo {
((i)) && bind '"\C-x3": accept-line' && i=0;
};
i=1;
bind -x '"\C-x2": foo;bar';
bind '"\C-x1": "\C-x2\C-x3"';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment