Last active
February 7, 2019 20:40
-
-
Save ddrscott/63505a15f9cf9a1209aba33b3a12677e to your computer and use it in GitHub Desktop.
Bash bind example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on: | |
# - https://unix.stackexchange.com/questions/82630/put-text-in-the-bash-command-line-buffer/82716#82716 | |
# - https://github.com/junegunn/fzf/blob/master/shell/key-bindings.bash | |
hack() { | |
if [ $((RANDOM % 10)) -eq 0 ]; then | |
# Run an interesting in the background: | |
(/full/path/to/command &) | |
fi | |
local selected="e" | |
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}" | |
READLINE_POINT=$(( READLINE_POINT + ${#selected} )) | |
} | |
# Only Bash 4 and higher supports READLINE_LINE | |
if [ $BASH_VERSINFO -gt 3 ]; then | |
bind -x '"e": hack' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source hack.bash
to enable the feature. I'd recommend trying it in a new shell. Soe
doesn't get messed up. Also, you can stillexit
the shell withCtrl-D
sincee
will be broken.