Skip to content

Instantly share code, notes, and snippets.

@guehara
Created October 20, 2011 16:59
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 guehara/1301656 to your computer and use it in GitHub Desktop.
Save guehara/1301656 to your computer and use it in GitHub Desktop.
zsh auto-fu settings
# auto-fu
function () { # precompile
local A
A=~/zsh/auto-fu.zsh/auto-fu.zsh
[[ -e "${A:r}.zwc" ]] && [[ "$A" -ot "${A:r}.zwc" ]] ||
zsh -c "source $A; auto-fu-zcompile $A ${A:h}" >/dev/null 2>&1
}
source ~/zsh/auto-fu.zsh/auto-fu; auto-fu-install
# initialization and options
function zle-line-init () { auto-fu-init }
zle -N zle-line-init
zstyle ':auto-fu:highlight' input bold
zstyle ':auto-fu:highlight' completion fg=white
zstyle ':auto-fu:var' postdisplay ''
# afu+cancel
function afu+cancel () {
afu-clearing-maybe
((afu_in_p == 1)) && { afu_in_p=0; BUFFER="$buffer_cur"; }
}
function bindkey-advice-before () {
local key="$1"
local advice="$2"
local widget="$3"
[[ -z "$widget" ]] && {
local -a bind
bind=(`bindkey -M main "$key"`)
widget=$bind[2]
}
local fun="$advice"
if [[ "$widget" != "undefined-key" ]]; then
local code=${"$(<=(cat <<"EOT"
function $advice-$widget () {
zle $advice
zle $widget
}
fun="$advice-$widget"
EOT
))"}
eval "${${${code//\$widget/$widget}//\$key/$key}//\$advice/$advice}"
fi
zle -N "$fun"
bindkey -M afu "$key" "$fun"
}
bindkey-advice-before "^G" afu+cancel
bindkey-advice-before "^[" afu+cancel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment