Skip to content

Commit

Permalink
feat: toggle between find/grep
Browse files Browse the repository at this point in the history
feat: multiple dirs
  • Loading branch information
phanen committed Apr 17, 2024
1 parent a9e0656 commit c75d1f3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
1 change: 1 addition & 0 deletions lua/fzf-lua-overlay/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local default_opts = {
dot_dir = '~',
dot_dirs = { '~', '~/b/stage/' },
notes_dir = '~/notes',
cache_dir = vim.fs.joinpath(vim.g.cache_dir or vim.fn.stdpath 'cache', 'fzf-lua-overlay'),
}
Expand Down
5 changes: 0 additions & 5 deletions lua/fzf-lua-overlay/overlay.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local cfg = require 'fzf-lua-overlay.config'.opts

local lsp_opt_fn = function(k)
return {
name = k,
Expand All @@ -8,9 +6,6 @@ local lsp_opt_fn = function(k)
end

local overlay = setmetatable({
find_dots = { name = 'files', opts = { cwd = cfg.dot_dir } },
grep_dots = { name = 'live_grep_native', opts = { cwd = cfg.dot_dir } },
grep_notes = { name = 'live_grep_native', opts = { cwd = cfg.notes_dir } },
todo_comment = { name = 'grep', opts = { search = 'TODO|HACK|PERF|NOTE|FIX', no_esc = true } },
}, {
__index = function(t, k)
Expand Down
16 changes: 16 additions & 0 deletions lua/fzf-lua-overlay/providers/find_dots.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local M = {}

local cfg = require('fzf-lua-overlay.config').opts

M.name = 'files'

-- 'live_grep_native'
M.opts = {
prompt = 'find_dots> ',
cwd = cfg.dot_dir,
cmd = ([[rg --color=never --files --hidden %s --follow -g "!.git"]]):format(
table.concat(cfg.dot_dirs, ' ')
),
}

return M
19 changes: 11 additions & 8 deletions lua/fzf-lua-overlay/providers/find_notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ return {
name = 'files',
opts = {
cwd = cfg.notes_dir,
-- stylua: ignore
actions = {
['ctrl-g'] = function(...) require('fzf-lua-overlay.actions').toggle_daily(...) end,
['ctrl-n'] = function(...) require('fzf-lua-overlay.actions').create_notes(...) end,
['ctrl-x'] = function(...) require('fzf-lua-overlay.actions').delete_files(...) end,
},
actions = {
['ctrl-g'] = function(...)
-- https://github.com/Bekaboo/nvim/blob/7ed3725c753753964eea6081bbd3cba304a3042f/lua/configs/fzf-lua.lua#L60
local last_query = require('fzf-lua').config.__resume_data.last_query
return require('fzf-lua-overlay').grep_notes({ query = last_query })
end,
['ctrl-n'] = function(...) require('fzf-lua-overlay.actions').create_notes(...) end,
['ctrl-x'] = function(...) require('fzf-lua-overlay.actions').delete_files(...) end,
},
fzf_opts = { ['--history'] = notes_history },
file_icons = false,
git_icons = false,
-- file_icons = false,
-- git_icons = false,
},
}
16 changes: 16 additions & 0 deletions lua/fzf-lua-overlay/providers/grep_dots.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local M = {}

local cfg = require('fzf-lua-overlay.config').opts

M.name = 'live_grep_native'

-- 'live_grep_native'
M.opts = {
prompt = 'grep_dots> ',
cwd = cfg.dot_dir,
cmd = ([[rg %s --column --line-number --no-heading --color=always --smart-case --max-columns=4096 -e]]):format(
table.concat(cfg.dot_dirs, ' ')
),
}

return M
18 changes: 18 additions & 0 deletions lua/fzf-lua-overlay/providers/grep_notes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local cfg = require('fzf-lua-overlay.config').opts

local notes_history = vim.fs.joinpath(cfg.cache_dir, 'notes_history')

return {
name = 'live_grep_native',
opts = {
cwd = cfg.notes_dir,
actions = {
['ctrl-g'] = function(...)
-- https://github.com/Bekaboo/nvim/blob/7ed3725c753753964eea6081bbd3cba304a3042f/lua/configs/fzf-lua.lua#L60
local last_query = require('fzf-lua').config.__resume_data.last_query
return require('fzf-lua-overlay').find_notes({ query = last_query })
end,
},
fzf_opts = { ['--history'] = notes_history },
},
}

0 comments on commit c75d1f3

Please sign in to comment.