# # Zle config # # fix Home and End keys bindkey '\eOH' beginning-of-line bindkey '\eOF' end-of-line # autoescape specials chars with urls autoload -U url-quote-magic zle -N self-insert url-quote-magic # insert sudo at beggining of current command insert-sudo-prefix () { local prefix prefix='sudo' if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then BUFFER="$prefix $BUFFER" CURSOR=$(($CURSOR + $#prefix + 1)) fi } zle -N insert-sudo-prefix bindkey "^b" insert-sudo-prefix # Clear screen and Tmux history clear-scrollback-and-screen () { zle clear-screen if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then tmux clear-history fi } zle -N clear-scrollback-and-screen bindkey '^l' clear-scrollback-and-screen # Refresh environment refresh-environment () { if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then source <(tmux show-environment | sed -r -e '/^-/d' -e 's/^([^=]+)=(.*)$/\1="\2"/') fi } refresh-environment-bykey () { zle -R "Updating environment..." refresh-environment sleep 0.3 } zle -N refresh-environment-bykey bindkey '^f' refresh-environment-bykey