diff options
Diffstat (limited to 'config/essentials/vis/fzf-mru.lua')
-rw-r--r-- | config/essentials/vis/fzf-mru.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/config/essentials/vis/fzf-mru.lua b/config/essentials/vis/fzf-mru.lua index 6c2510d..455d083 100644 --- a/config/essentials/vis/fzf-mru.lua +++ b/config/essentials/vis/fzf-mru.lua @@ -1,12 +1,23 @@ -local module = {} -module.fzfmru_filepath = os.getenv("XDG_CACHE_HOME") .. "/vis-fzf-mru" -module.fzfmru_path = "fzf" -module.fzfmru_args = "--height=40%" -module.fzfmru_history = 20 +--[[ +Based on https://github.com/peaceant/vis-fzf-mru +Changes made: +- stylua +- renamed module to M +- renamed fzfmru to fzf +- height to 40% +- use XDG_CACHE_HOME +- ignore exit code 130 +--]] + +local M = {} +M.fzf_filepath = os.getenv("XDG_CACHE_HOME") .. "/vis-fzf-mru" +M.fzf_path = "fzf" +M.fzf_args = "--height=40%" +M.fzf_history = 20 local function read_mru() local mru = {} - local f = io.open(module.fzfmru_filepath) + local f = io.open(M.fzf_filepath) if f == nil then return end for line in f:lines() do table.insert(mru, line) end f:close() @@ -25,13 +36,13 @@ local function write_mru(win) -- check duplicate if file_path == mru[1] then return end - local f = io.open(module.fzfmru_filepath, "w+") + local f = io.open(M.fzf_filepath, "w+") if f == nil then return end table.insert(mru, 1, file_path) for i, k in ipairs(mru) do - if i > module.fzfmru_history then break end + if i > M.fzf_history then break end if i == 1 or k ~= file_path then f:write(string.format("%s\n", k)) end @@ -43,8 +54,8 @@ end vis.events.subscribe(vis.events.WIN_OPEN, write_mru) vis:command_register("fzfmru", function(argv) - local command = "cat " .. module.fzfmru_filepath .. " | " .. - module.fzfmru_path .. " " .. module.fzfmru_args .. " " .. + local command = "cat " .. M.fzf_filepath .. " | " .. + M.fzf_path .. " " .. M.fzf_args .. " " .. table.concat(argv, " ") local file = io.popen(command) @@ -72,4 +83,4 @@ vis:command_register("fzfmru", function(argv) return true end) -return module +return M |