From 572d07cd3eeb0915dd237e023ac6c0761d53d8f9 Mon Sep 17 00:00:00 2001 From: urosm Date: Fri, 13 Sep 2024 20:29:20 +0200 Subject: [PATCH] vis: introduce find_root --- .config/vis/visrc.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua index d0fb44d..8b0a36e 100644 --- a/.config/vis/visrc.lua +++ b/.config/vis/visrc.lua @@ -195,3 +195,21 @@ e.subscribe(e.WIN_STATUS, function(win) set_title(win.file.name or '[No Name]') end end) + +-- find root +e.subscribe(e.WIN_OPEN, function(win) + if not win.file.path then return end + local dir = win.file.path + local home = os.getenv('HOME') + if not dir:find(home) then return end + while true do + dir = dir:match('^(.+)/[^/]+$') or home + local _, find = vis:pipe(('find %s ! -path %s -prune -type d -name .git'):format(dir, dir)) + if find or dir == home then + local cmd = ('cd "%s"'):format(dir) + vis:info(cmd) + vis:command(cmd) + break + end + end +end)