From 72626a9158fb6b06ac894f2d6382b757f5f16e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Fri, 9 Dec 2022 13:00:59 +0100 Subject: [PATCH] zsh: input --- .../herbstluftwm/executable_panel-handler | 2 +- dot_config/zsh/include/input.zsh | 127 ++++++ dot_config/zsh/include/kitty.zsh | 404 +++++++++++++----- dot_config/zsh/include/options.zsh | 3 - dot_zimrc | 2 +- 5 files changed, 420 insertions(+), 118 deletions(-) create mode 100644 dot_config/zsh/include/input.zsh diff --git a/dot_config/herbstluftwm/executable_panel-handler b/dot_config/herbstluftwm/executable_panel-handler index 82fe4b5..cbbff50 100644 --- a/dot_config/herbstluftwm/executable_panel-handler +++ b/dot_config/herbstluftwm/executable_panel-handler @@ -271,7 +271,7 @@ hc --idle | { first_loop=0 done -} | lemonbar -f "Noto Sans Mono-10" -f "Symbols Nerd Font-10" -a30 -B "$col_bg" -F "$col_fg" -u 1 | sh +} | lemonbar -f "Hack-10" -f "Symbols Nerd Font-10" -a30 -B "$col_bg" -F "$col_fg" -u 1 | sh #} | lemonbar -f "DejaVu Sans-9" -f "Font Awesome-9" -f "Symbols Nerd Font-9" #} | tee >(lemonbar -f "DejaViu Sans-9" -f "Font Awesome-9" ) diff --git a/dot_config/zsh/include/input.zsh b/dot_config/zsh/include/input.zsh new file mode 100644 index 0000000..8a37ae6 --- /dev/null +++ b/dot_config/zsh/include/input.zsh @@ -0,0 +1,127 @@ +# Adapted from https://github.com/zimfw/input +# +# The MIT License (MIT) +# +# Copyright (c) 2015-2016 Matt Hamilton and contributors +# Copyright (c) 2016-2020 Eric Nielsen, Matt Hamilton and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Editor and input char assignment +# + +bindkey -e + +[[ ${TERM} != dumb ]] && () { + + # Use human-friendly identifiers. + zmodload -F zsh/terminfo +b:echoti +p:terminfo + typeset -gA key_info + key_info=( + Control '\C-' + ControlLeft '\e[1;5D \e[5D \eOd \eOD' + ControlRight '\e[1;5C \e[5C \eOc \eOC' + Escape '\e' + Meta '\M-' + Backspace '^?' + Delete '^[[3~' + BackTab "${terminfo[kcbt]}" + Left "${terminfo[kcub1]}" + Down "${terminfo[kcud1]}" + Right "${terminfo[kcuf1]}" + Up "${terminfo[kcuu1]}" + End "${terminfo[kend]}" + F1 "${terminfo[kf1]}" + F2 "${terminfo[kf2]}" + F3 "${terminfo[kf3]}" + F4 "${terminfo[kf4]}" + F5 "${terminfo[kf5]}" + F6 "${terminfo[kf6]}" + F7 "${terminfo[kf7]}" + F8 "${terminfo[kf8]}" + F9 "${terminfo[kf9]}" + F10 "${terminfo[kf10]}" + F11 "${terminfo[kf11]}" + F12 "${terminfo[kf12]}" + Home "${terminfo[khome]}" + Insert "${terminfo[kich1]}" + PageDown "${terminfo[knp]}" + PageUp "${terminfo[kpp]}" + ) + + # Bind the keys + + local key + for key (${(s: :)key_info[ControlLeft]}) bindkey ${key} backward-word + for key (${(s: :)key_info[ControlRight]}) bindkey ${key} forward-word + + bindkey ${key_info[Backspace]} backward-delete-char + bindkey ${key_info[Delete]} delete-char + + if [[ -n ${key_info[Home]} ]] bindkey ${key_info[Home]} beginning-of-line + if [[ -n ${key_info[End]} ]] bindkey ${key_info[End]} end-of-line + + if [[ -n ${key_info[PageUp]} ]] bindkey ${key_info[PageUp]} up-line-or-history + if [[ -n ${key_info[PageDown]} ]] bindkey ${key_info[PageDown]} down-line-or-history + + if [[ -n ${key_info[Insert]} ]] bindkey ${key_info[Insert]} overwrite-mode + + if [[ -n ${key_info[Left]} ]] bindkey ${key_info[Left]} backward-char + if [[ -n ${key_info[Right]} ]] bindkey ${key_info[Right]} forward-char + +autoload -U down-line-or-beginning-search \ + && zle -N up-line-or-beginning-search \ + && bindkey -M emacs "${key_info[Up]}" up-line-or-beginning-search + +autoload -U up-line-or-beginning-search \ + && zle -N down-line-or-beginning-search \ + && bindkey -M emacs "${key_info[Down]}" down-line-or-beginning-search + + # Expandpace. + bindkey ' ' magic-space + + # Bind insert-last-word even in viins mode + bindkey "${key_info[Escape]}." insert-last-word + bindkey "${key_info[Escape]}_" insert-last-word + + # to edit command-line in EDITOR + autoload -Uz edit-command-line && zle -N edit-command-line && \ + bindkey "${key_info[Control]}x${key_info[Control]}e" edit-command-line + + # Bind to go to the previous menu item. + if [[ -n ${key_info[BackTab]} ]] bindkey ${key_info[BackTab]} reverse-menu-complete + + # Use smart URL pasting and escaping. + autoload -Uz bracketed-paste-url-magic && zle -N bracketed-paste bracketed-paste-url-magic + autoload -Uz url-quote-magic && zle -N self-insert url-quote-magic + + if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then + # Enable application mode when zle is active + start-application-mode() { + echoti smkx + } + stop-application-mode() { + echoti rmkx + } + + autoload -Uz add-zle-hook-widget \ + && add-zle-hook-widget -Uz line-init start-application-mode \ + && add-zle-hook-widget -Uz line-finish stop-application-mode + fi +} diff --git a/dot_config/zsh/include/kitty.zsh b/dot_config/zsh/include/kitty.zsh index 36a8f3e..1eeb5d6 100644 --- a/dot_config/zsh/include/kitty.zsh +++ b/dot_config/zsh/include/kitty.zsh @@ -1,113 +1,291 @@ -return -local csi="\x1b\x5b27u\x1b\x5b" -local ESCAPE="${csi}27u" -local ENTER="${csi}13u" -local TAB="${csi}9u" -local BACKSPACE="${csi}127u" -local INSERT="${csi}2~" -local DELETE="${csi}3~" -local LEFT="${csi}1D" -local RIGHT="${csi}1C" -local UP="${csi}1A" -local DOWN="${csi}1B" -local PAGE_UP="${csi}5~" -local PAGE_DOWN="${csi}6~" -local HOME="${csi}1H or 7 ~" -local END="${csi}1F or 8 ~" -local CAPS_LOCK="${csi}57358u" -local SCROLL_LOCK="${csi}57359u" -local NUM_LOCK="${csi}57360u" -local PRINT_SCREEN="${csi}57361u" -local PAUSE="${csi}57362u" -local MENU="${csi}57363u" -local F1="${csi}1P or 11 ~" -local F2="${csi}1Q or 12 ~" -local F3="${csi}1R or 13 ~" -local F4="${csi}1S or 14 ~" -local F5="${csi}15~" -local F6="${csi}17~" -local F7="${csi}18~" -local F8="${csi}19~" -local F9="${csi}20~" -local F10="${csi}21~" -local F11="${csi}23~" -local F12="${csi}24~" -local F13="${csi}57376u" -local F14="${csi}57377u" -local F15="${csi}57378u" -local F16="${csi}57379u" -local F17="${csi}57380u" -local F18="${csi}57381u" -local F19="${csi}57382u" -local F20="${csi}57383u" -local F21="${csi}57384u" -local F22="${csi}57385u" -local F23="${csi}57386u" -local F24="${csi}57387u" -local F25="${csi}57388u" -local F26="${csi}57389u" -local F27="${csi}57390u" -local F28="${csi}57391u" -local F29="${csi}57392u" -local F30="${csi}57393u" -local F31="${csi}57394u" -local F32="${csi}57395u" -local F33="${csi}57396u" -local F34="${csi}57397u" -local F35="${csi}57398u" -local KP_0="${csi}57399u" -local KP_1="${csi}57400u" -local KP_2="${csi}57401u" -local KP_3="${csi}57402u" -local KP_4="${csi}57403u" -local KP_5="${csi}57404u" -local KP_6="${csi}57405u" -local KP_7="${csi}57406u" -local KP_8="${csi}57407u" -local KP_9="${csi}57408u" -local KP_DECIMAL="${csi}57409u" -local KP_DIVIDE="${csi}57410u" -local KP_MULTIPLY="${csi}57411u" -local KP_SUBTRACT="${csi}57412u" -local KP_ADD="${csi}57413u" -local KP_ENTER="${csi}57414u" -local KP_EQUAL="${csi}57415u" -local KP_SEPARATOR="${csi}57416u" -local KP_LEFT="${csi}57417u" -local KP_RIGHT="${csi}57418u" -local KP_UP="${csi}57419u" -local KP_DOWN="${csi}57420u" -local KP_PAGE_UP="${csi}57421u" -local KP_PAGE_DOWN="${csi}57422u" -local KP_HOME="${csi}57423u" -local KP_END="${csi}57424u" -local KP_INSERT="${csi}57425u" -local KP_DELETE="${csi}57426u" -local KP_BEGIN="${csi}1E or 57427 ~" -local MEDIA_PLAY="${csi}57428u" -local MEDIA_PAUSE="${csi}57429u" -local MEDIA_PLAY_PAUSE="${csi}57430u" -local MEDIA_REVERSE="${csi}57431u" -local MEDIA_STOP="${csi}57432u" -local MEDIA_FAST_FORWARD="${csi}57433u" -local MEDIA_REWIND="${csi}57434u" -local MEDIA_TRACK_NEXT="${csi}57435u" -local MEDIA_TRACK_PREVIOUS="${csi}57436u" -local MEDIA_RECORD="${csi}57437u" -local LOWER_VOLUME="${csi}57438u" -local RAISE_VOLUME="${csi}57439u" -local MUTE_VOLUME="${csi}57440u" -local LEFT_SHIFT="${csi}57441u" -local LEFT_CONTROL="${csi}57442u" -local LEFT_ALT="${csi}57443u" -local LEFT_SUPER="${csi}57444u" -local LEFT_HYPER="${csi}57445u" -local LEFT_META="${csi}57446u" -local RIGHT_SHIFT="${csi}57447u" -local RIGHT_CONTROL="${csi}57448u" -local RIGHT_ALT="${csi}57449u" -local RIGHT_SUPER="${csi}57450u" -local RIGHT_HYPER="${csi}57451u" -local RIGHT_META="${csi}57452u" -local ISO_LEVEL3_SHIFT="${csi}57453u" -local ISO_LEVEL5_SHIFT="${csi}57454u" +local esc="\x1b" +local csi="${esc}[" +local KITTY_ESCAPE="${csi}27u" +local KITTY_ENTER="${csi}13u" +local KITTY_TAB="${csi}9u" +local KITTY_BACKSPACE="${csi}127u" +local KITTY_INSERT="${csi}2~" +local KITTY_DELETE="${csi}3~" +local KITTY_LEFT="${csi}1D" +local KITTY_RIGHT="${csi}1C" +local KITTY_UP="${csi}1A" +local KITTY_DOWN="${csi}1B" +local KITTY_PAGE_UP="${csi}5~" +local KITTY_PAGE_DOWN="${csi}6~" +local KITTY_HOME="${csi}1H or 7 ~" +local KITTY_END="${csi}1F or 8 ~" +local KITTY_CAPS_LOCK="${csi}57358u" +local KITTY_SCROLL_LOCK="${csi}57359u" +local KITTY_NUM_LOCK="${csi}57360u" +local KITTY_PRINT_SCREEN="${csi}57361u" +local KITTY_PAUSE="${csi}57362u" +local KITTY_MENU="${csi}57363u" +local KITTY_F1="${csi}1P or 11 ~" +local KITTY_F2="${csi}1Q or 12 ~" +local KITTY_F3="${csi}1R or 13 ~" +local KITTY_F4="${csi}1S or 14 ~" +local KITTY_F5="${csi}15~" +local KITTY_F6="${csi}17~" +local KITTY_F7="${csi}18~" +local KITTY_F8="${csi}19~" +local KITTY_F9="${csi}20~" +local KITTY_F10="${csi}21~" +local KITTY_F11="${csi}23~" +local KITTY_F12="${csi}24~" +local KITTY_F13="${csi}57376u" +local KITTY_F14="${csi}57377u" +local KITTY_F15="${csi}57378u" +local KITTY_F16="${csi}57379u" +local KITTY_F17="${csi}57380u" +local KITTY_F18="${csi}57381u" +local KITTY_F19="${csi}57382u" +local KITTY_F20="${csi}57383u" +local KITTY_F21="${csi}57384u" +local KITTY_F22="${csi}57385u" +local KITTY_F23="${csi}57386u" +local KITTY_F24="${csi}57387u" +local KITTY_F25="${csi}57388u" +local KITTY_F26="${csi}57389u" +local KITTY_F27="${csi}57390u" +local KITTY_F28="${csi}57391u" +local KITTY_F29="${csi}57392u" +local KITTY_F30="${csi}57393u" +local KITTY_F31="${csi}57394u" +local KITTY_F32="${csi}57395u" +local KITTY_F33="${csi}57396u" +local KITTY_F34="${csi}57397u" +local KITTY_F35="${csi}57398u" +local KITTY_KP_0="${csi}57399u" +local KITTY_KP_1="${csi}57400u" +local KITTY_KP_2="${csi}57401u" +local KITTY_KP_3="${csi}57402u" +local KITTY_KP_4="${csi}57403u" +local KITTY_KP_5="${csi}57404u" +local KITTY_KP_6="${csi}57405u" +local KITTY_KP_7="${csi}57406u" +local KITTY_KP_8="${csi}57407u" +local KITTY_KP_9="${csi}57408u" +local KITTY_KP_DECIMAL="${csi}57409u" +local KITTY_KP_DIVIDE="${csi}57410u" +local KITTY_KP_MULTIPLY="${csi}57411u" +local KITTY_KP_SUBTRACT="${csi}57412u" +local KITTY_KP_ADD="${csi}57413u" +local KITTY_KP_ENTER="${csi}57414u" +local KITTY_KP_EQUAL="${csi}57415u" +local KITTY_KP_SEPARATOR="${csi}57416u" +local KITTY_KP_LEFT="${csi}57417u" +local KITTY_KP_RIGHT="${csi}57418u" +local KITTY_KP_UP="${csi}57419u" +local KITTY_KP_DOWN="${csi}57420u" +local KITTY_KP_PAGE_UP="${csi}57421u" +local KITTY_KP_PAGE_DOWN="${csi}57422u" +local KITTY_KP_HOME="${csi}57423u" +local KITTY_KP_END="${csi}57424u" +local KITTY_KP_INSERT="${csi}57425u" +local KITTY_KP_DELETE="${csi}57426u" +local KITTY_KP_BEGIN="${csi}1E or 57427 ~" +local KITTY_MEDIA_PLAY="${csi}57428u" +local KITTY_MEDIA_PAUSE="${csi}57429u" +local KITTY_MEDIA_PLAY_PAUSE="${csi}57430u" +local KITTY_MEDIA_REVERSE="${csi}57431u" +local KITTY_MEDIA_STOP="${csi}57432u" +local KITTY_MEDIA_FAST_FORWARD="${csi}57433u" +local KITTY_MEDIA_REWIND="${csi}57434u" +local KITTY_MEDIA_TRACK_NEXT="${csi}57435u" +local KITTY_MEDIA_TRACK_PREVIOUS="${csi}57436u" +local KITTY_MEDIA_RECORD="${csi}57437u" +local KITTY_LOWER_VOLUME="${csi}57438u" +local KITTY_RAISE_VOLUME="${csi}57439u" +local KITTY_MUTE_VOLUME="${csi}57440u" +local KITTY_LEFT_SHIFT="${csi}57441u" +local KITTY_LEFT_CONTROL="${csi}57442u" +local KITTY_LEFT_ALT="${csi}57443u" +local KITTY_LEFT_SUPER="${csi}57444u" +local KITTY_LEFT_HYPER="${csi}57445u" +local KITTY_LEFT_META="${csi}57446u" +local KITTY_RIGHT_SHIFT="${csi}57447u" +local KITTY_RIGHT_CONTROL="${csi}57448u" +local KITTY_RIGHT_ALT="${csi}57449u" +local KITTY_RIGHT_SUPER="${csi}57450u" +local KITTY_RIGHT_HYPER="${csi}57451u" +local KITTY_RIGHT_META="${csi}57452u" +local KITTY_ISO_LEVEL3_SHIFT="${csi}57453u" +local KITTY_ISO_LEVEL5_SHIFT="${csi}57454u" + +local -A KITTY_CTRL KITTY_ALT KITTY_CTRL_ALT +# a-z +for i in {97..126} +do + KITTY_CTRL[${(#)i}]="${csi}$i;5u" + KITTY_ALT[${(#)i}]="${csi}$i;3u" + KITTY_CTRL_ALT[${(#)i}]="${csi}$i;8u" +done + +if (( ${+ENABLE_KITTY_STUFF} )) +then + start-kitty-keys() { + echo -n "${csi}>1u" + } + stop-kitty-keys() { + echo -n "${csi}" end-of-buffer-or-history + bindkey -M emacs "^[?" which-command + bindkey -M emacs "^[A" accept-and-hold + bindkey -M emacs "^[B" backward-word + bindkey -M emacs "^[C" capitalize-word + bindkey -M emacs "^[D" kill-word + bindkey -M emacs "^[F" forward-word + bindkey -M emacs "^[G" get-line + bindkey -M emacs "^[H" run-help + bindkey -M emacs "^[L" down-case-word + bindkey -M emacs "^[N" history-search-forward + bindkey -M emacs "^[OA" up-line-or-beginning-search + bindkey -M emacs "^[OB" down-line-or-beginning-search + bindkey -M emacs "^[OC" forward-char + bindkey -M emacs "^[OD" backward-char + bindkey -M emacs "^[OF" end-of-line + bindkey -M emacs "^[OH" beginning-of-line + bindkey -M emacs "^[Oc" forward-word + bindkey -M emacs "^[Od" backward-word + bindkey -M emacs "^[P" history-search-backward + bindkey -M emacs "^[Q" push-line + bindkey -M emacs "^[S" spell-word + bindkey -M emacs "^[T" transpose-words + bindkey -M emacs "^[U" up-case-word + bindkey -M emacs "^[W" copy-region-as-kill + bindkey -M emacs "^[[1;5C" forward-word + bindkey -M emacs "^[[1;5D" backward-word + bindkey -M emacs "^[[200~" bracketed-paste + bindkey -M emacs "^[[2~" overwrite-mode + bindkey -M emacs "^[[3~" delete-char + bindkey -M emacs "^[[5C" forward-word + bindkey -M emacs "^[[5D" backward-word + bindkey -M emacs "^[[5~" up-line-or-history + bindkey -M emacs "^[[6~" down-line-or-history + bindkey -M emacs "^[[A" up-line-or-history + bindkey -M emacs "^[[B" down-line-or-history + bindkey -M emacs "^[[C" forward-char + bindkey -M emacs "^[[D" backward-char + bindkey -M emacs "^[[Z" reverse-menu-complete + bindkey -M emacs "^[_" insert-last-word + bindkey -M emacs "^[a" accept-and-hold + bindkey -M emacs "^[b" backward-word + bindkey -M emacs "^[c" fzf-cd-widget + bindkey -M emacs "^[d" kill-word + bindkey -M emacs "^[f" forward-word + bindkey -M emacs "^[g" get-line + bindkey -M emacs "^[h" run-help + bindkey -M emacs "^[l" down-case-word + bindkey -M emacs "^[n" history-search-forward + bindkey -M emacs "^[p" history-search-backward + bindkey -M emacs "^[q" push-line + bindkey -M emacs "^[s" spell-word + bindkey -M emacs "^[t" transpose-words + bindkey -M emacs "^[u" up-case-word + bindkey -M emacs "^[w" copy-region-as-kill + bindkey -M emacs "^[x" execute-named-cmd + bindkey -M emacs "^[y" yank-pop + bindkey -M emacs "^[z" execute-last-named-cmd + bindkey -M emacs "^[|" vi-goto-column + bindkey -M emacs "^[~" _bash_complete-word + bindkey -M emacs "^[^?" backward-kill-word + bindkey -M emacs "^_" undo + bindkey -M emacs " " magic-space + bindkey -M emacs "!"-"~" self-insert + bindkey -M emacs "^?" backward-delete-char + bindkey -M emacs "\M-^@"-"\M-^?" self-insert +fi diff --git a/dot_config/zsh/include/options.zsh b/dot_config/zsh/include/options.zsh index 0baa5f8..f40c907 100644 --- a/dot_config/zsh/include/options.zsh +++ b/dot_config/zsh/include/options.zsh @@ -14,6 +14,3 @@ setopt hist_verify # show command with history expansion to user befo setopt share_history # share command history data HISTSIZE=50000 SAVEHIST=10000 - -# estabilish basic keybinding -bindkey -e diff --git a/dot_zimrc b/dot_zimrc index d50b2e7..9cc5e1e 100644 --- a/dot_zimrc +++ b/dot_zimrc @@ -1,5 +1,5 @@ #zmodule zsh-users/zsh-syntax-highlighting -zmodule input +#zmodule input zmodule romkatv/powerlevel10k --use degit zmodule agkozak/zsh-z zmodule $confdir/completion --name custom-completion --fpath .