Skip to content

Commit 9a2c49f

Browse files
committed
Add telescope theme config support
Signed-off-by: Aaron Hallaert <[email protected]>
1 parent 5637d80 commit 9a2c49f

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

lua/advanced_git_search/telescope/pickers/init.lua

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ local telescope_ags_mappings = require("advanced_git_search.telescope.mappings")
1414

1515
local M = {}
1616

17+
local config = require("advanced_git_search.utils.config")
18+
1719
--- Opens a Telescope window with all files changed on the current branch
1820
--- Only committed changes will be displayed
1921
M.changed_on_branch = function()
22+
local theme_opts = config.telescope_theme("changed_on_branch")
23+
2024
pickers
21-
.new({
25+
.new(vim.tbl_extend("force", {
2226
results_title = "Modified "
2327
.. git_utils.base_branch()
2428
.. " -> "
2529
.. git_utils.current_branch(),
2630
sorter = sorters.get_fuzzy_file(),
2731
finder = telescope_ags_finders.changed_files_on_current_branch_finder(),
2832
previewer = telescope_ags_previewers.changed_files_on_current_branch_previewer(),
29-
})
33+
}, theme_opts))
3034
:find()
3135
end
3236

@@ -36,8 +40,10 @@ M.diff_branch_file = function()
3640
local current_branch = git_utils.current_branch()
3741
local bufnr = vim.fn.bufnr()
3842

43+
local theme_opts = config.telescope_theme("diff_branch_file")
44+
3945
pickers
40-
.new({
46+
.new(vim.tbl_extend("force", {
4147
results_title = "Local branches :: *" .. current_branch,
4248
prompt_title = "Branch name",
4349
finder = telescope_ags_finders.git_branches_finder(),
@@ -51,7 +57,7 @@ M.diff_branch_file = function()
5157
)
5258
return true
5359
end,
54-
})
60+
}, theme_opts))
5561
:find()
5662
end
5763

@@ -62,6 +68,8 @@ M.diff_commit_line = function()
6268
local s_start = vim.fn.getpos("'<")[2]
6369
local s_end = vim.fn.getpos("'>")[2]
6470

71+
local theme_opts = config.telescope_theme("diff_commit_line")
72+
6573
if s_start == 0 or s_end == 0 then
6674
vim.notify(
6775
"No visual selection",
@@ -74,7 +82,7 @@ M.diff_commit_line = function()
7482
-- git log -L741,751:'app/models/patients/patient.rb'\
7583
-- --format='%C(auto)%h \t %as \t %C(green)%an _ %Creset %s'
7684
pickers
77-
.new({
85+
.new(vim.tbl_extend("force", {
7886
results_title = "Commits that affected the selected lines",
7987
prompt_title = "Commit message",
8088
finder = telescope_ags_finders.git_log_location_finder(
@@ -95,18 +103,20 @@ M.diff_commit_line = function()
95103
telescope_ags_mappings.show_entire_commit(map)
96104
return true
97105
end,
98-
})
106+
}, theme_opts))
99107
:find()
100108
end
101109

102110
--- Opens a Telescope window with a list of previous commits.
103111
--- Query is used to filter the results based on the
104112
--- content of the commit (added or removed text).
105113
M.search_log_content = function()
114+
local theme_opts = config.telescope_theme("search_log_content")
115+
106116
-- git log -L741,751:'app/models/patients/patient.rb' \
107117
-- --format='%C(auto)%h \t %as \t %C(green)%an _ %Creset %s'
108118
pickers
109-
.new({
119+
.new(vim.tbl_extend("force", {
110120
results_title = "Commits",
111121
prompt_title = "Git log content (added, removed or updated text)",
112122
finder = telescope_ags_finders.git_log_content_finder({}),
@@ -120,7 +130,7 @@ M.search_log_content = function()
120130
telescope_ags_mappings.show_entire_commit(map)
121131
return true
122132
end,
123-
})
133+
}, theme_opts))
124134
:find()
125135
end
126136

@@ -129,10 +139,12 @@ M.search_log_content_file = function()
129139
-- local file_name = vim.fn.expand("%")
130140
-- local relative_file_name = vim.fn.expand("%:~:.")
131141

142+
local theme_opts = config.telescope_theme("search_log_content_file")
143+
132144
-- git log -L741,751:'app/models/patients/patient.rb' \
133145
-- --format='%C(auto)%h \t %as \t %C(green)%an _ %Creset %s'
134146
pickers
135-
.new({
147+
.new(vim.tbl_extend("force", {
136148
results_title = "Commits",
137149
prompt_title = "Git log content (added, removed or updated text in this file)",
138150
finder = telescope_ags_finders.git_log_content_finder({
@@ -149,15 +161,18 @@ M.search_log_content_file = function()
149161

150162
return true
151163
end,
152-
})
164+
}, theme_opts))
153165
:find()
154166
end
155167

156168
-- Opens a Telescope window with a list of git commits which changed the current file (renames included)
157169
M.diff_commit_file = function()
158170
local bufnr = vim.fn.bufnr()
171+
172+
local theme_opts = config.telescope_theme("search_log_content_file")
173+
159174
pickers
160-
.new({
175+
.new(vim.tbl_extend("force", {
161176
results_title = "Commits that affected this file (renamed files included)",
162177
prompt_title = "Commit message",
163178
finder = telescope_ags_finders.git_log_file_finder(bufnr),
@@ -175,14 +190,16 @@ M.diff_commit_file = function()
175190

176191
return true
177192
end,
178-
})
193+
}, theme_opts))
179194
:find()
180195
end
181196

182197
--- Opens a Telescope window with all reflog entries
183198
M.checkout_reflog = function()
199+
local theme_opts = config.telescope_theme("checkout_reflog")
200+
184201
pickers
185-
.new({
202+
.new(vim.tbl_extend("force", {
186203
results_title = "Git Reflog, <CR> to checkout",
187204
finder = finders.new_oneshot_job(
188205
require("advanced_git_search.commands.find").reflog()
@@ -192,16 +209,18 @@ M.checkout_reflog = function()
192209
telescope_ags_mappings.checkout_reflog_entry(map)
193210
return true
194211
end,
195-
})
212+
}, theme_opts))
196213
:find()
197214
end
198215

199216
--- Opens a selector for all advanced git search functions
200217
M.show_custom_functions = function()
201218
local keys = global_picker.keys("telescope")
202219

220+
local theme_opts = config.telescope_theme("show_custom_functions")
221+
203222
pickers
204-
.new({
223+
.new(vim.tbl_extend("force", {
205224
prompt_title = "Git actions",
206225
finder = finders.new_table(keys),
207226
sorter = sorters.get_fuzzy_file(),
@@ -221,7 +240,7 @@ M.show_custom_functions = function()
221240

222241
return true
223242
end,
224-
})
243+
}, theme_opts))
225244
:find()
226245
end
227246

lua/advanced_git_search/utils/config.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ M.git_diff_flags = function()
3232
return git_diff_flags
3333
end
3434

35+
M.telescope_theme = function(function_name)
36+
local themes = require("telescope.themes")
37+
local theme = config["telescope_theme"][function_name] or {}
38+
39+
local theme_opts = {}
40+
-- apply theme
41+
if type(theme) == "table" then
42+
theme_opts = vim.tbl_extend("force", theme_opts, theme)
43+
elseif type(theme) == "string" then
44+
if themes["get_" .. theme] == nil then
45+
vim.notify_once(
46+
"advanced git search theme »" .. theme .. "« not found",
47+
vim.log.levels.WARN
48+
)
49+
else
50+
theme_opts = themes["get_" .. theme](theme_opts)
51+
end
52+
end
53+
54+
return theme_opts
55+
end
56+
3557
M.git_flags = function()
3658
local git_flags = config["git_flags"] or {}
3759

0 commit comments

Comments
 (0)