Skip to content

Instantly share code, notes, and snippets.

@crater2150
Last active December 8, 2016 10:51
Show Gist options
  • Save crater2150/2dce1f14bd5d5233cdad965ce0a2f6f7 to your computer and use it in GitHub Desktop.
Save crater2150/2dce1f14bd5d5233cdad965ce0a2f6f7 to your computer and use it in GitHub Desktop.
accept and infer for people forgetting to use it before pressing enter
# if there is currently something typed, accept-and-infer-next-history like usual
# if the input line is empty, recall the last command and infer based on that
# needs deduplication of history disabled! (unsetopt HIST_SAVE_NO_DUPS HIST_IGNORE_ALL_DUPS)
local function accept-or-recall-then-infer-history() {
if [[ -z $PREBUFFER$BUFFER ]]; then
zle up-line-or-history
zle infer-next-history
else
zle accept-and-infer-next-history -- "$@"
fi
}
zle -N accept-or-recall-and-infer-history
bindkey "\e^M" accept-or-recall-and-infer-history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment