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 |
source hack.bash
to enable the feature. I'd recommend trying it in a new shell. So e
doesn't get messed up. Also, you can still exit
the shell with Ctrl-D
since e
will be broken.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be a template to make
e
passthrough thehack()
function without a new line, but for some reason, a new line is emitted which spoils the effect.