You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
719 B

9 months ago
# Modify the input line before it runs
function page() {
#commands=(${(@s:/:)BUFFER})
# Gets the words
words=(${(z)BUFFER})
# If there isn't anythng typed, fall back to old tab binding
if [ ${#words} -lt 1 ]; then
zle ${enterBehaviour:-accept-line}
return
fi
lastCommand="$(printf "%s\n" words | tac | sed -E '/^(\||\&\&|\|\|)$/,$d' | tac)"
lastCommand="${(s:\n:)lastCommand}"
case "$BUFFER" in
*"--help" | *"-h" )
BUFFER="$BUFFER | bat"
;;
esac
zle ${enterBehaviour:-accept-line}
}
enterBehaviour="accept-line"
binding=$(bindkey '^M')
[[ $binding =~ 'undefined-key' ]] || enterBehaviour=$binding[(s: :w)2]
unset original_binding
zle -N page
# Bind to the Enter key
bindkey '^M' page