Create live-image for Grit OS

keys.zsh 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # create a zkbd compatible hash;
  2. # to add other keys to this hash, see: man 5 terminfo
  3. typeset -A key
  4. key[Home]=${terminfo[khome]}
  5. key[End]=${terminfo[kend]}
  6. key[Insert]=${terminfo[kich1]}
  7. key[Delete]=${terminfo[kdch1]}
  8. key[Up]=${terminfo[kcuu1]}
  9. key[Down]=${terminfo[kcud1]}
  10. key[Left]=${terminfo[kcub1]}
  11. key[Right]=${terminfo[kcuf1]}
  12. key[PageUp]=${terminfo[kpp]}
  13. key[PageDown]=${terminfo[knp]}
  14. # setup key accordingly
  15. [[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
  16. [[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
  17. [[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
  18. [[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
  19. [[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
  20. [[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
  21. [[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
  22. [[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
  23. [[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history
  24. [[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history
  25. # Finally, make sure the terminal is in application mode, when zle is
  26. # active. Only then are the values from $terminfo valid.
  27. if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
  28. function zle-line-init () {
  29. printf '%s' "${terminfo[smkx]}"
  30. }
  31. function zle-line-finish () {
  32. printf '%s' "${terminfo[rmkx]}"
  33. }
  34. zle -N zle-line-init
  35. zle -N zle-line-finish
  36. fi