From dc067c860d5e76d38dc7a94355a89fed31cc6660 Mon Sep 17 00:00:00 2001
From: Marty Oehme <marty.oehme@gmail.com>
Date: Sat, 4 Jan 2025 10:45:06 +0100
Subject: [PATCH] vifm: Add zoxide integration

If zoxide is found on the system, vifm will automatically add any paths
traversed into the zoxide database.
It will also have a new internal command 'zoxide' with which you can
open a menu to search all zoxide-known paths - it is also added as a
mapping to <space>z.
---
 terminal/.config/vifm/vifmrc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/terminal/.config/vifm/vifmrc b/terminal/.config/vifm/vifmrc
index 55c2f90..0e96c5c 100644
--- a/terminal/.config/vifm/vifmrc
+++ b/terminal/.config/vifm/vifmrc
@@ -325,6 +325,14 @@ nnoremap ,T :!vifm-thumbnailer -r -t %u %c<cr>
 " batch rename or delete files in current dir
 nnoremap ,r :!vidir<cr>
 
+if executable('zoxide')
+    " integrate zoxide search and add any vifm-visited paths automatically
+    " adapted from https://q2a.vifm.info/949/how-can-i-integrate-zoxide-into-vifm
+    command! zoxide :set noquickview | :execute 'cd' fnameescape(system('zoxide query --interactive "%a" 2>/dev/tty')) '%IU' | redraw
+    nnoremap <space>z :zoxide<cr>
+    autocmd DirEnter * !zoxide add %d %i
+endif
+
 " allows preview to work for normal view and single pane view
 noremap <silent> w : if layoutis('only')
                    \|     if &lines + 50 < &columns | vsplit | else | split | endif