aboutsummaryrefslogtreecommitdiffstats
path: root/.config/zsh/functions/01_editor.zsh
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2021-09-28 22:50:56 +0200
committerDavid Runge <dave@sleepmap.de>2021-09-28 22:50:56 +0200
commit3ac8e0f994839f3c972033bcb12421081ebeb683 (patch)
tree2a4f05cac56559686ea5d7aee8703e7511662c47 /.config/zsh/functions/01_editor.zsh
parenta640bb766699706b4975416b85acd30191b79fa3 (diff)
downloaddotfiles-3ac8e0f994839f3c972033bcb12421081ebeb683.tar.gz
dotfiles-3ac8e0f994839f3c972033bcb12421081ebeb683.tar.bz2
dotfiles-3ac8e0f994839f3c972033bcb12421081ebeb683.tar.xz
dotfiles-3ac8e0f994839f3c972033bcb12421081ebeb683.zip
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.
Diffstat (limited to '.config/zsh/functions/01_editor.zsh')
-rw-r--r--.config/zsh/functions/01_editor.zsh124
1 files changed, 124 insertions, 0 deletions
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