1
0
Fork 0

vis: introduce find_root

main
urosm 2024-09-13 20:29:20 +02:00
parent 2471d78a02
commit 572d07cd3e
1 changed files with 18 additions and 0 deletions

View File

@ -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)