summaryrefslogtreecommitdiff
path: root/config/essentials/vis/fzf-mru.lua
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-08-15 18:53:47 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-08-15 18:53:47 +0200
commit4073294204effdf65e1182d1769120a5fcd9d348 (patch)
treea1a961e382a74a032dfe48ace0cb53bd89234a29 /config/essentials/vis/fzf-mru.lua
parent93bdfbb5d7b16a44cb23e6ee2bffd3eef368f8fc (diff)
checkpoint
Diffstat (limited to 'config/essentials/vis/fzf-mru.lua')
-rw-r--r--config/essentials/vis/fzf-mru.lua86
1 files changed, 0 insertions, 86 deletions
diff --git a/config/essentials/vis/fzf-mru.lua b/config/essentials/vis/fzf-mru.lua
deleted file mode 100644
index 8408dd7..0000000
--- a/config/essentials/vis/fzf-mru.lua
+++ /dev/null
@@ -1,86 +0,0 @@
---[[
-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") or (os.getenv("HOME") .. "/.local/share")).. "/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(M.fzf_filepath)
- if f == nil then return end
- for line in f:lines() do table.insert(mru, line) end
- f:close()
-
- return mru
-end
-
-local function write_mru(win)
- local file_path = win.file.path
- local mru = read_mru()
-
- -- check if mru data exists
- if mru == nil then mru = {} end
- -- check if we opened any file
- if file_path == nil then return end
- -- check duplicate
- if file_path == mru[1] then return end
-
- 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 > M.fzf_history then break end
- if i == 1 or k ~= file_path then
- f:write(string.format("%s\n", k))
- end
- end
-
- f:close()
-end
-
-vis.events.subscribe(vis.events.WIN_OPEN, write_mru)
-
-vis:command_register("fzfmru", function(argv)
- local command = "cat " .. M.fzf_filepath .. " | " ..
- M.fzf_path .. " " .. M.fzf_args .. " " ..
- table.concat(argv, " ")
-
- local file = io.popen(command)
- local output = file:read()
- local _, _, status = file:close()
-
- if status == 0 then
- vis:command(string.format("e '%s'", output))
- elseif status == 1 then
- vis:info(string.format(
- "fzf-open: No match. Command %s exited with return value %i.",
- command, status))
- elseif status == 2 then
- vis:info(string.format(
- "fzf-open: Error. Command %s exited with return value %i.",
- command, status))
- elseif status ~= 130 then
- vis:info(string.format(
- "fzf-open: Unknown exit status %i. command %s exited with return value %i",
- status, command, status, status))
- end
-
- vis:redraw()
-
- return true
-end)
-
-return M