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)