20_zle.zsh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #
  2. # Zle config
  3. #
  4. # fix Home and End keys
  5. bindkey '\eOH' beginning-of-line
  6. bindkey '\eOF' end-of-line
  7. # autoescape specials chars with urls
  8. autoload -U url-quote-magic
  9. zle -N self-insert url-quote-magic
  10. # insert sudo at beggining of current command
  11. insert-sudo-prefix () {
  12. local prefix
  13. prefix='sudo'
  14. if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
  15. BUFFER="$prefix $BUFFER"
  16. CURSOR=$(($CURSOR + $#prefix + 1))
  17. fi
  18. }
  19. zle -N insert-sudo-prefix
  20. bindkey "^b" insert-sudo-prefix
  21. # Clear screen and Tmux history
  22. clear-scrollback-and-screen () {
  23. zle clear-screen
  24. if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then
  25. tmux clear-history
  26. fi
  27. }
  28. zle -N clear-scrollback-and-screen
  29. bindkey '^l' clear-scrollback-and-screen
  30. # Refresh environment
  31. refresh-environment () {
  32. if [[ -n "${TMUX}" ]] && (( $+commands[tmux] )); then
  33. source <(tmux show-environment | sed -r -e '/^-/d' -e 's/^([^=]+)=(.*)$/\1="\2"/')
  34. fi
  35. }
  36. refresh-environment-bykey () {
  37. zle -R "Updating environment..."
  38. refresh-environment
  39. sleep 0.3
  40. }
  41. zle -N refresh-environment-bykey
  42. bindkey '^f' refresh-environment-bykey