Skip to content

Commit

Permalink
feat: add config to disable telescope previewer #3
Browse files Browse the repository at this point in the history
  • Loading branch information
agoodshort committed Feb 6, 2024
1 parent d0a7c71 commit e40ca42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require("telescope").setup({
extensions = {
git_submodules = {
git_cmd = "lazygit",
previewer = true,
terminal_id = 9,
},
},
Expand All @@ -47,10 +48,11 @@ require("telescope").setup({

### Extension Specs

| Property | Type | Default Value | Description |
|-------------|---------|---------------|----------------------------------|
| git_cmd | string? | "lazygit" | git TUI command of your choice |
| terminal_id | number? | 9 | Terminal ID toggleterm will use |
| Property | Type | Default Value | Description |
|-------------|---------|---------------|-------------------------------------------|
| git_cmd | string? | "lazygit" | git TUI command of your choice |
| previewer | boolean | true | Preview submodule changes in Telescope |
| terminal_id | number? | 9 | Terminal ID toggleterm will use |

## Roadmap

Expand Down
43 changes: 24 additions & 19 deletions lua/telescope/_extensions/git_submodules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local previewers = require("telescope.previewers")
local entry_display = require("telescope.pickers.entry_display")
local conf = require("telescope.config").values
local Terminal = require("toggleterm.terminal").Terminal

local setup_opts = {
git_cmd = "lazygit",
previewer = true,
terminal_id = 9,
}

Expand Down Expand Up @@ -121,6 +121,28 @@ local show_repos = function(opts)
if table.getn(items) == 1 then
open_git_tool(opts, items[1][2])
else
local previewer_config = nil
if opts.previewer == true then
previewer_config = require("telescope.previewers").new_buffer_previewer({
define_preview = function(self, entry, status)
local dir_name = vim.fn.substitute(vim.fn.getcwd(), "^.*/", "", "")
local t = {}
if entry.value == dir_name then
local s = vim.fn.system("git status -s")
for chunk in string.gmatch(s, "[^\n]+") do
t[#t + 1] = chunk
end
else
local s = vim.fn.system("git -C " .. entry.value .. " status -s")
for chunk in string.gmatch(s, "[^\n]+") do
t[#t + 1] = chunk
end
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, t)
end,
})
end

pickers
.new(opts, {
prompt_title = "Git Submodules",
Expand Down Expand Up @@ -176,24 +198,7 @@ local show_repos = function(opts)
end)
return true
end,
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry, status)
local dir_name = vim.fn.substitute(vim.fn.getcwd(), "^.*/", "", "")
local t = {}
if entry.value == dir_name then
local s = vim.fn.system("git status -s")
for chunk in string.gmatch(s, "[^\n]+") do
t[#t + 1] = chunk
end
else
local s = vim.fn.system("git -C " .. entry.value .. " status -s")
for chunk in string.gmatch(s, "[^\n]+") do
t[#t + 1] = chunk
end
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, t)
end,
}),
previewer = previewer_config,
})
:find()
end
Expand Down

0 comments on commit e40ca42

Please sign in to comment.