diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-05-27 21:43:34 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-05-27 21:43:34 +0200 |
| commit | ac0a20194f46fdeb1ab553aa2079cee4e22d5f13 (patch) | |
| tree | 3336d6015dfaffdb34e22f62fa06685dc20373f8 /.config | |
| parent | 5f3de5cef82eacef7287192e35a53b8a0d4dbc26 (diff) | |
| download | dotfiles-ac0a20194f46fdeb1ab553aa2079cee4e22d5f13.tar.gz dotfiles-ac0a20194f46fdeb1ab553aa2079cee4e22d5f13.zip | |
Add conditional check to see if nvim is running for prompt's vi-mode
Diffstat (limited to '.config')
| -rw-r--r-- | .config/zsh/.zshrc | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 4ac5612..46942ee 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -155,11 +155,6 @@ function set-prompt() { %{%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%{└─%{["%{$(tput setaf 226)%}""%{$(tput blink)%}"%{$%}"%{$(tput sgr0)%}"%{%G]%}%}%}%}" } -#function update-mode-file() { -# set-prompt -# echo "$VI_MODE" >| ~/.vi-mode -# tmux refresh-client -S -#} function update-mode-file() { set-prompt local current_mode=$(cat ~/.vi-mode) @@ -167,6 +162,23 @@ function update-mode-file() { if [[ "$new_mode" != "$current_mode" ]]; then echo "$new_mode" >| ~/.vi-mode + fi + + tmux refresh-client -S +} + +function check-nvim-running() { + if pgrep -x "nvim" > /dev/null; then + VI_MODE="" + update-mode-file + tmux refresh-client -S + else + if [[ ${KEYMAP} == vicmd || ${KEYMAP} == vi-cmd-mode ]]; then + VI_MODE=$(normal-mode) + elif [[ ${KEYMAP} == main || ${KEYMAP} == viins || ${KEYMAP} == '' ]]; then + VI_MODE=$(insert-mode) + fi + update-mode-file tmux refresh-client -S fi } @@ -205,6 +217,39 @@ TRAPWINCH() { # Trap the WINCH signal to update the mode file on window size cha update-mode-file } +function nvim-listener() { + local prev_nvim_status="inactive" + local nvim_pid="" + + while true; do + local current_nvim_pid=$(pgrep -x "nvim") + + if [[ -n "$current_nvim_pid" && "$current_nvim_pid" != "$nvim_pid" ]]; then + # Neovim started + prev_nvim_status="active" + nvim_pid="$current_nvim_pid" + VI_MODE="" # Clear VI_MODE to show Neovim mode + update-mode-file + tmux refresh-client -S + elif [[ -z "$current_nvim_pid" && "$prev_nvim_status" == "active" ]]; then + # Neovim stopped + prev_nvim_status="inactive" + nvim_pid="" + if [[ ${KEYMAP} == vicmd || ${KEYMAP} == vi-cmd-mode ]]; then + VI_MODE=$(normal-mode) + elif [[ ${KEYMAP} == main || ${KEYMAP} == viins || ${KEYMAP} == '' ]]; then + VI_MODE=$(insert-mode) + fi + update-mode-file + tmux refresh-client -S + fi + # Add a delay + #sleep 0.5 + done +} + +# Start Neovim listener in the background +nvim-listener &! set-prompt RPROMPT='%(?..[%F{196}%?%f] )' |
