aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-09-15 15:47:07 -0500
committerToby Vincent <tobyv13@gmail.com>2022-09-15 15:47:07 -0500
commit1f870aa8921468a8a06f9672b1fe16b7ea05c404 (patch)
tree8ada31ea3921b40870623d457cbc8c91b87ad890
parent2144c89e92a967f7fd1b1ad41e3d3ceb7468ace0 (diff)
feat(zsh): add zsh-vi-mode plugin to improve zsh's vi mode
-rw-r--r--sheldon/.config/sheldon/plugins.toml11
-rw-r--r--wsl/.local/share/zsh-wsl/zsh-wsl.plugin.zsh58
-rw-r--r--zsh/.config/zsh/.zshrc24
3 files changed, 74 insertions, 19 deletions
diff --git a/sheldon/.config/sheldon/plugins.toml b/sheldon/.config/sheldon/plugins.toml
index 2148c77..b853ec9 100644
--- a/sheldon/.config/sheldon/plugins.toml
+++ b/sheldon/.config/sheldon/plugins.toml
@@ -7,17 +7,17 @@ github = 'romkatv/zsh-defer'
defer = { value = 'zsh-defer source "{{ file }}"', each = true }
comp = { value = 'mkdir -p "$XDG_DATA_HOME/zsh/site-functions"; ln -sf "{{ file }}" "$XDG_DATA_HOME/zsh/site-functions/_{{ name }}"', each = true }
+[plugins.zsh-vi-mode]
+github = "jeffreytse/zsh-vi-mode"
+
[plugins.zsh-wsl]
-inline = 'test -f ~/.local/share/zsh-wsl/zsh-wsl.plugin.zsh && zsh-defer source ~/.local/share/zsh-wsl/zsh-wsl.plugin.zsh'
+local = '~/.local/share/zsh-wsl'
+profiles = ["WSL2"]
[plugins.zsh-syntax-highlighting]
github = "zsh-users/zsh-syntax-highlighting"
apply = ["defer"]
-[plugins.zsh-shift-select]
-github = "jirutka/zsh-shift-select"
-apply = ["defer"]
-
[plugins.zsh-fzf-history-search]
github = "joshskidmore/zsh-fzf-history-search"
apply = ["defer"]
@@ -44,4 +44,3 @@ use = ["{{ name }}.zsh"]
[plugins.compinit]
inline = 'mkdir -p $XDG_CACHE_HOME/zsh && autoload -Uz compinit && zsh-defer compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION'
-
diff --git a/wsl/.local/share/zsh-wsl/zsh-wsl.plugin.zsh b/wsl/.local/share/zsh-wsl/zsh-wsl.plugin.zsh
index 70236cf..23bb567 100644
--- a/wsl/.local/share/zsh-wsl/zsh-wsl.plugin.zsh
+++ b/wsl/.local/share/zsh-wsl/zsh-wsl.plugin.zsh
@@ -13,9 +13,13 @@ export DISPLAY="$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}')":0
export BROWSER=wslview
export XDG_RUNTIME_DIR=/tmp/xdg
export GPG_TTY="$(tty)"
+export SHELDON_PROFILE="wsl"
-alias wsl=wsl.exe
+alias wsl="/mnt/c/Windows/system32/wsl.exe"
+alias powershell="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
+alias pwsh="/mnt/c/Program Files/PowerShell/7/pwsh.exe"
alias ykman='/mnt/c/Program\ Files/Yubico/YubiKey\ Manager/ykman.exe'
+
alias pip2="DISPLAY= pip2"
alias pip3="DISPLAY= pip3"
alias pip3.7="DISPLAY= pip3.7"
@@ -61,3 +65,55 @@ wsl_cmd_proxy() {
winget() { wsl_cmd_proxy "winget.exe" "$@"; }
scoop() { wsl_cmd_proxy "scoop" "$@"; }
+
+zvm_vi_yank () {
+ zvm_yank
+ printf %s "${CUTBUFFER}" | win32yank.exe -i
+ zvm_exit_visual_mode
+}
+
+zvm_vi_put_after () {
+ local head= foot=
+ local content=$(win32yank.exe -o)
+ local offset=1
+ if [[ ${content: -1} == $'\n' ]]
+ then
+ local pos=${CURSOR}
+ for ((; $pos<$#BUFFER; pos++)) do
+ if [[ ${BUFFER:$pos:1} == $'\n' ]]
+ then
+ pos=$pos+1
+ break
+ fi
+ done
+ if zvm_is_empty_line
+ then
+ head=${BUFFER:0:$pos}
+ foot=${BUFFER:$pos}
+ else
+ head=${BUFFER:0:$pos}
+ foot=${BUFFER:$pos}
+ if [[ $pos == $#BUFFER ]]
+ then
+ content=$'\n'${content:0:-1}
+ pos=$pos+1
+ fi
+ fi
+ offset=0
+ BUFFER="${head}${content}${foot}"
+ CURSOR=$pos
+ else
+ if zvm_is_empty_line
+ then
+ head="${BUFFER:0:$((CURSOR-1))}"
+ foot="${BUFFER:$CURSOR}"
+ else
+ head="${BUFFER:0:$CURSOR}"
+ foot="${BUFFER:$((CURSOR+1))}"
+ fi
+ BUFFER="${head}${BUFFER:$CURSOR:1}${content}${foot}"
+ CURSOR=$CURSOR+$#content
+ fi
+ zvm_highlight clear
+ zvm_highlight custom $(($#head+$offset)) $(($#head+$#content+$offset))
+}
diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc
index 8a4b446..b579661 100644
--- a/zsh/.config/zsh/.zshrc
+++ b/zsh/.config/zsh/.zshrc
@@ -18,6 +18,7 @@ setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
setopt share_history # share command history data
+setopt nonomatch
zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh/zcompcache
@@ -28,20 +29,9 @@ alias untar="tar -zxvf"
alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
alias tlmgr='/usr/share/texmf-dist/scripts/texlive/tlmgr.pl --usermode'
-bindkey -e
-bindkey '^ ' autosuggest-accept
-bindkey '^[[Z' reverse-menu-complete
-bindkey '^[[1~' beginning-of-line
-bindkey '^[[4~' end-of-line
-bindkey '^[[3~' delete-char
-bindkey '^[[1;5C' forward-word
-bindkey '^[[1;5D' backward-word
-
-# typeset -A ZSH_HIGHLIGHT_STYLES
-# export ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
+export SHELDON_PROFILE="$(uname -r | sed 's/^.*-//g' 2>/dev/null)"
export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line)
export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion)
-# https://github.com/zsh-users/zsh-autosuggestions#suggestion-highlight-style
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#4f4738"
if command -v fd >/dev/null 2>&1; then
@@ -95,3 +85,13 @@ fi
command -v starship >/dev/null 2>&1 && source <(starship init zsh)
command -v sheldon >/dev/null 2>&1 && source <(sheldon source)
+
+zvm_after_init() {
+ bindkey '^ ' autosuggest-accept
+ bindkey '^[[Z' reverse-menu-complete
+ bindkey '^[[1~' beginning-of-line
+ bindkey '^[[4~' end-of-line
+ bindkey '^[[3~' delete-char
+ bindkey '^[[1;5C' forward-word
+ bindkey '^[[1;5D' backward-word
+}