Last active
November 14, 2023 18:28
-
-
Save akemrir/b1c791e46dccd119e855ed8e0938dfc9 to your computer and use it in GitHub Desktop.
Revisions
-
Karol Jakusz-Gostomski revised this gist
Nov 14, 2023 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,17 +51,17 @@ _G.fif_grep = function(opts) local tags = vim.opt.tags:get() opts = opts or {} if opts.buffer ~= "" and opts.buffer ~= nil and opts.search ~= "" and opts.search ~= nil then local buf = cutTagBasePath(tags, opts.buffer) opts.prompt = "fif :'" .. buf .. "' :'" .. opts.search .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(buf) .. ' ' .. vim.fn.shellescape(opts.search) elseif opts.buffer ~= "" and opts.buffer ~= nil then local buf = cutTagBasePath(tags, opts.buffer) opts.prompt = "fif :'" .. buf .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(buf) elseif opts.search ~= "" and opts.search ~= nil then opts.prompt = "fif :'" .. opts.search .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(opts.search) else opts.prompt = "fif❯ " end -
Karol Jakusz-Gostomski revised this gist
Nov 14, 2023 . No changes.There are no files selected for viewing
-
Karol Jakusz-Gostomski created this gist
Nov 14, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,107 @@ local function getPath(str) return str:match("(.*[/\\])") end local function cutTagBasePath(tags, str) for _, v in pairs(tags) do print(v) str = str:gsub(getPath(v), "") end return str end local function GetTableLng(tbl) local getN = 0 for _ in pairs(tbl) do getN = getN + 1 end return getN end local function fn_transform_tbl(tbl) -- format all entires as “fzf-lua compatible” return vim.tbl_map(function(x) -- 1 tag -- 2 filename -- 5 line number -- 8 decorated tag line -- additional job print("fn_transform_tbl") local el = Split(x, "\t") local tag = el[1] local filename = el[2] local path = getPath(el[GetTableLng(el)]) local no = Split(el[5], ":")[2] local target = string.format("%s%s:%s:%s", path, filename, no, tag) -- print(target) return target end, tbl) end function Split(s, delimiter) local result = {}; for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match); end return result; end _G.fif_grep = function(opts) local fzf_lua = require 'fzf-lua' local tags = vim.opt.tags:get() opts = opts or {} if opts.buffer ~= "" and opts.buffer ~= nil then local buf = cutTagBasePath(tags, opts.buffer) opts.prompt = "fif :'" .. buf .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(buf) elseif opts.search ~= "" and opts.search ~= nil then opts.prompt = "fif :'" .. opts.search .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(opts.search) elseif opts.buffer ~= "" and opts.buffer ~= nil and opts.search ~= "" and opts.search ~= nil then local buf = cutTagBasePath(tags, opts.buffer) opts.prompt = "fif :'" .. buf .. "' :'" .. opts.search .. "'❯ " opts.fzf_cli_args = '-q ' .. vim.fn.shellescape(buf) .. ' ' .. vim.fn.shellescape(opts.search) else opts.prompt = "fif❯ " end print(opts.fzf_cli_args) opts.git_icons = true opts.file_icons = true opts.color_icons = true -- setup default actions for edit, quickfix, etc opts.actions = fzf_lua.defaults.actions.files -- see preview overview for more info on previewers opts.previewer = "builtin" opts.actions = { -- ["<bind1>"] = { fn = function(selected) end, reload = true } -- ["<o>"] = { fn = require'fzf-lua'.actions.file_edit, reload = true } ["default"] = function(selected, o) require 'fzf-lua'.actions.file_edit_or_qf(fn_transform_tbl(selected), o) end, } local cmdt = { "tag-dec" } for _, value in pairs(tags) do table.insert(cmdt, value) end for _, value in pairs({ "|", "rg", "-v", "'^!'" }) do table.insert(cmdt, value) end local cmd = table.concat(cmdt, " ") print(cmd) return fzf_lua.fzf_exec(cmd, opts) end vim.keymap.set("n", ";t", function() _G.fif_grep({ search = "" }) end) vim.keymap.set("n", "<leader>t", function() _G.fif_grep({ search = "" }) end) vim.keymap.set("n", ";T", function() _G.fif_grep({ search = vim.fn.expand('<cword>') }) end) vim.keymap.set("n", "<leader>T", function() _G.fif_grep({ search = vim.fn.expand('<cword>') }) end) vim.keymap.set("n", ";o", function() _G.fif_grep({ search = "", buffer = vim.fn.expand('%') }) end) vim.keymap.set("n", "<leader>o", function() _G.fif_grep({ search = "", buffer = vim.fn.expand('%') }) end) vim.keymap.set("n", ";O", function() _G.fif_grep({ search = vim.fn.expand('<cword>'), buffer = vim.fn.expand('%') }) end) vim.keymap.set("n", "<leader>O", function() _G.fif_grep({ search = vim.fn.expand('<cword>'), buffer = vim.fn.expand('%') }) end)