From f05fbfb4451959850315218bb031c5fe4c6dbb14 Mon Sep 17 00:00:00 2001 From: Mike Vink <59492084+ivi-vink@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:43:40 +0000 Subject: updates --- mut/vis/visrc.lua | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'mut/vis/visrc.lua') diff --git a/mut/vis/visrc.lua b/mut/vis/visrc.lua index 898df9c..4f87b50 100644 --- a/mut/vis/visrc.lua +++ b/mut/vis/visrc.lua @@ -19,6 +19,7 @@ format.formatters.terraform = format.stdio_formatter("terraform fmt -", {on_save vis.events.subscribe(vis.events.INIT, function() vis:command"set shell '/usr/bin/bash'" vis:command"set edconfhooks on" + vis:command"set change256colors off" vis:command"set theme lemonsoda" vis:map(m.INSERT, '"', '+') @@ -39,6 +40,9 @@ end) local files = {} vis.events.subscribe(vis.events.WIN_OPEN, function(win) vis:command"set cul on" + vis:command"set number" + vis:command"set relativenumber" + vis:command"set change256colors off" local radix = files[vis.win.file.path] for p, i in pairs(files) do if (radix == nil) or (radix >= i) then @@ -50,7 +54,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) end end) -vis:map(m.NORMAL, "b", function() +vis:map(m.NORMAL, "b", function() local keys = {} for k in pairs(files) do if k ~= vis.win.file.path then table.insert(keys, k) end end if next(keys) == nil then @@ -64,35 +68,41 @@ vis:map(m.NORMAL, "b", function() return true; end) -vis:map(m.NORMAL, "~", function() - vis:command("cd " .. vis.win.file.path:match("(.+)/[^/]+$")) +local parent = function(filename) + if filename ~= nil then + return filename:match("(.+)/[^/]+$") + end + return nil +end + +local lfcd = function(cd_or_select_path) + local code, result, err = vis:pipe("", "lf --print-selection " .. cd_or_select_path) + vis:command("cd " .. err) + if result then + vis:command("e " .. result) + end + return true; +end + +vis:map(m.NORMAL, "~", function() + vis:command("cd " .. (parent(vis.win.file.path) or ".")) return true; end) -vis:map(m.NORMAL, "f", function() - local code, result, err = vis:pipe("", "vis-open .") +vis:map(m.NORMAL, "", function() + local code, result, err = vis:pipe("", "vis-open " .. (parent(vis.win.file.path) or ".")) if result then - if not os.execute("cd " .. result) then vis:command("e " .. result) else - vis:command("cd " .. result) - local code, result, err = vis:pipe("", "lf --print-selection") - if not result then return true end - local lines = {} - for line in result:gmatch("[^\n]+") do table.insert(lines, line) end - if lines[1] then - vis:command("e " .. lines[1]) - end + return lfcd(result) end return true; end return true; end) -vis:map(m.NORMAL, "-", function() - local code, result, err = vis:pipe("", "lf --print-selection") - vis:command("cd " .. err) - if result then - vis:command("e " .. result) - end - return true; +vis:map(m.NORMAL, "-", function() + return lfcd(parent(vis.win.file.path) or "") +end) +vis:map(m.NORMAL, "_", function() + return lfcd(".") end) -- cgit v1.2.3