vis: introduce find_root
parent
2471d78a02
commit
572d07cd3e
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue