From ebf4274c5b8dc0496b283ac577d1eb685f9b8e4f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 8 Mar 2022 10:15:33 +0100 Subject: [PATCH 1/2] nvim: Add mapping for finding hidden files While f searches files, now searches for hidden files. Simple addition but can be very useful if you work for example in dotfolder directories or similar. Now I just need to find a way to do the same for live_grep. The functionality is there (live_grep can take the same `{hidden=true}` argument as find_files) but terminal emulators don't distinguish between and so there is no convenient mapping for it yet. --- nvim/.config/nvim/lua/maps.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index ad47d62..a1be15f 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -130,6 +130,9 @@ map.n.nore['S'] = [[:lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())]] -- fuzzy find files in cwd map.n.nore['f'] = [[:lua require 'telescope.builtin'.find_files()]] +-- fuzzy find hidden files in cwd +map.n.nore[''] = + [[:lua require 'telescope.builtin'.find_files({hidden=true})]] -- general full-text search in cwd with rg map.n.nore['F'] = [[:lua require 'telescope.builtin'.live_grep()]] From 4d048aecd8306473bd3606c2cb9377755922de03 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 8 Mar 2022 22:47:33 +0100 Subject: [PATCH 2/2] bootstrap: Update package list Updated package list for March 2022. Contains some small fixes for missing packages like transmission khal and nsxiv that I have started using more heavily and removed some redundancies, especially around the big X switch some time back. Generally, no huge changes. Fixes #1. --- nvim/.config/nvim/lua/personal/openpdf.lua | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 nvim/.config/nvim/lua/personal/openpdf.lua diff --git a/nvim/.config/nvim/lua/personal/openpdf.lua b/nvim/.config/nvim/lua/personal/openpdf.lua new file mode 100644 index 0000000..ed7a187 --- /dev/null +++ b/nvim/.config/nvim/lua/personal/openpdf.lua @@ -0,0 +1,63 @@ +-- will open the pdf file for whatever file i am currently viewing. +-- POC only and only useful in a ALMP context for now. +local fn = vim.fn + +local function isDirectory(ftype) + if ftype == 'directory' then return true end + return false +end + +local function isFile(ftype) + if ftype == 'file' then return true end + return false +end + +local function cleanPath(path) + if path:match("^~") then path = os.getenv("HOME") .. path:sub(2) end + return path +end +-- Returns a set of all files at the target directory, as well +-- as subdirectories if the recursive argument is set to true. +-- Set has the form { "full/path/name.md" = "name.md" } +local function get_all_files(path, recursive) + local f = {} + path = cleanPath(path) + + local handle = vim.loop.fs_scandir(path) + while handle do + local name, ftype = vim.loop.fs_scandir_next(handle) + if not name then break end + + if isDirectory(ftype) and recursive then + local subdir = get_all_files(path .. "/" .. name, true) + for k, v in pairs(subdir) do f[tostring(k)] = v end + end + + if isFile(ftype) then f[tostring(path .. "/" .. name)] = name end + end + + return f +end + +local function get_basename() + local name = fn.expand("%:t") + return string.gsub(name, ".md", "") +end + +local function find_pdf(dir, bibkey) + local pdfs = get_all_files(dir) + for k, v in pairs(pdfs) do if v:find(bibkey, 0, true) then return k end end +end + +local function open_pdf(name) fn.jobstart("zathura '" .. name .. "'") end + +local function openCurrentPdf() + local fname = get_basename() + local pdf_path = find_pdf( + "/home/marty/projects/jobs/almp/output/Literature", + fname) + print(pdf_path) + open_pdf(pdf_path) +end + +return {open = openCurrentPdf}