Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Oct 11, 2022
1 parent 36cc6c8 commit efbcede
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lua/obsidian/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,31 @@ end
command.search = function(client, data)
local base_cmd = vim.tbl_flatten { util.SEARCH_CMD, { "--column", "--line-number", "--no-heading" } }

if vim.fn.exists "*fzf#vim#grep" and vim.fn.exists "*fzf#vim#with_preview" then
-- Search with fzf.vim
local grep_cmd =
vim.tbl_flatten { base_cmd, { "--color=always", "--", vim.fn.shellescape(data.args), tostring(client.dir) } }
local has_telescope, telescope = pcall(require, "telescope.builtin")

vim.api.nvim_call_function("fzf#vim#grep", {
table.concat(grep_cmd, " "),
true,
vim.api.nvim_call_function("fzf#vim#with_preview", {}),
false,
})
elseif vim.fn.exists ":Telescope" then
if has_telescope then
-- Search with telescope.nvim
local builtin = require "telescope.builtin"

local vimgrep_arguments = vim.tbl_flatten { base_cmd, {
"--with-filename",
"--color=never",
} }

if data.args:len() > 0 then
builtin.grep_string { cwd = tostring(client.dir), search = data.args, vimgrep_arguments = vimgrep_arguments }
telescope.grep_string { cwd = tostring(client.dir), search = data.args, vimgrep_arguments = vimgrep_arguments }
else
builtin.live_grep { cwd = tostring(client.dir), vimgrep_arguments = vimgrep_arguments }
telescope.live_grep { cwd = tostring(client.dir), vimgrep_arguments = vimgrep_arguments }
end
elseif vim.fn.exists "*fzf#vim#grep" and vim.fn.exists "*fzf#vim#with_preview" then
-- Search with fzf.vim
local grep_cmd =
vim.tbl_flatten { base_cmd, { "--color=always", "--", vim.fn.shellescape(data.args), tostring(client.dir) } }

vim.api.nvim_call_function("fzf#vim#grep", {
table.concat(grep_cmd, " "),
true,
vim.api.nvim_call_function("fzf#vim#with_preview", {}),
false,
})
else
echo.err "Either fzf.vim or telescope.nvim is required for :ObsidianSearch command"
end
Expand Down

0 comments on commit efbcede

Please sign in to comment.