From 3ac8e0f994839f3c972033bcb12421081ebeb683 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 28 Sep 2021 22:50:56 +0200 Subject: zsh: move includes to XDG compliant locations .config/zsh/{functions,includes}/*: Move functions and includes to XDG compliant locations. .zshrc: Include functions and other includes from XDG compliant locations. Remove use of prepend-sudo function. --- .config/zsh/functions/01_editor.zsh | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 .config/zsh/functions/01_editor.zsh (limited to '.config/zsh/functions/01_editor.zsh') diff --git a/.config/zsh/functions/01_editor.zsh b/.config/zsh/functions/01_editor.zsh new file mode 100644 index 0000000..1484a92 --- /dev/null +++ b/.config/zsh/functions/01_editor.zsh @@ -0,0 +1,124 @@ +# Exposes information about the Zsh Line Editor via the $editor_info associative +# array. +function editor-info { + # Clean up previous $editor_info. + unset editor_info + typeset -gA editor_info + + if [[ "$KEYMAP" == 'vicmd' ]]; then + zstyle -s ':editor:info:keymap:alternate' format 'REPLY' + editor_info[keymap]="$REPLY" + else + zstyle -s ':editor:info:keymap:primary' format 'REPLY' + editor_info[keymap]="$REPLY" + + if [[ "$ZLE_STATE" == *overwrite* ]]; then + zstyle -s ':editor:info:keymap:primary:overwrite' format 'REPLY' + editor_info[overwrite]="$REPLY" + else + zstyle -s ':editor:info:keymap:primary:insert' format 'REPLY' + editor_info[overwrite]="$REPLY" + fi + fi + + unset REPLY + + zle reset-prompt + zle -R +} +zle -N editor-info + +# Updates editor information when the keymap changes. +function zle-keymap-select { + zle editor-info +} +zle -N zle-keymap-select + +# Enables terminal application mode and updates editor information. +function zle-line-init { + # The terminal must be in application mode when ZLE is active for $terminfo + # values to be valid. + if (( $+terminfo[smkx] )); then + # Enable terminal application mode. + echoti smkx + fi + + # Update editor information. + zle editor-info +} +zle -N zle-line-init + +# Disables terminal application mode and updates editor information. +function zle-line-finish { + # The terminal must be in application mode when ZLE is active for $terminfo + # values to be valid. + if (( $+terminfo[rmkx] )); then + # Disable terminal application mode. + echoti rmkx + fi + + # Update editor information. + zle editor-info +} +zle -N zle-line-finish + +# Toggles emacs overwrite mode and updates editor information. +function overwrite-mode { + zle .overwrite-mode + zle editor-info +} +zle -N overwrite-mode + +# Enters vi insert mode and updates editor information. +function vi-insert { + zle .vi-insert + zle editor-info +} +zle -N vi-insert + +# Moves to the first non-blank character then enters vi insert mode and updates +# editor information. +function vi-insert-bol { + zle .vi-insert-bol + zle editor-info +} +zle -N vi-insert-bol + +# Enters vi replace mode and updates editor information. +function vi-replace { + zle .vi-replace + zle editor-info +} +zle -N vi-replace + +# Expands .... to ../.. +function expand-dot-to-parent-directory-path { + if [[ $LBUFFER = *.. ]]; then + LBUFFER+='/..' + else + LBUFFER+='.' + fi +} +zle -N expand-dot-to-parent-directory-path + +# Displays an indicator when completing. +function expand-or-complete-with-indicator { + local indicator + zstyle -s ':editor:info:completing' format 'indicator' + print -Pn "$indicator" + zle expand-or-complete + zle redisplay +} +zle -N expand-or-complete-with-indicator + +# Inserts 'sudo ' at the beginning of the line. +function prepend-sudo { + if [[ "$BUFFER" != su(do|)\ * ]]; then + BUFFER="sudo $BUFFER" + (( CURSOR += 5 )) + fi +} +zle -N prepend-sudo + +# Reset to default key bindings. +bindkey -d -- cgit v1.2.3-54-g00ecf