1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
local SHOULD_RELOAD_TELESCOPE = true
local reloader = function()
if SHOULD_RELOAD_TELESCOPE then
Reload "plenary"
Reload "telescope"
Reload "alpha.telescope.setup"
end
end
local fb_actions = require("telescope").extensions.file_browser.actions
local actions = require "telescope.actions"
local my_actions = require "alpha.telescope.my_actions"
local M = {}
function M.project_files()
local opts = { show_untracked = true } -- define here if you want to define something
local ok = pcall(require("telescope.builtin").git_files, opts)
if not ok then
require("telescope.builtin").find_files(opts)
end
end
function M.branches()
require("telescope.builtin").git_branches {
attach_mappings = function(_, map)
map("i", "<c-j>", actions.git_create_branch)
map("n", "<c-j>", actions.git_create_branch)
return true
end,
}
end
function M.search_config()
require("telescope.builtin").git_files {
prompt_title = "< Dotfiles >",
cwd = "$HOME/.dotfiles",
show_untracked = true,
}
end
M.find_nvim_config = function()
require("telescope.builtin").find_files {
prompt_title = "< Neovim >",
cwd = "$HOME/.config/nvim/",
}
end
M.find_nvim_plugin = function()
require("telescope.builtin").find_files {
prompt_title = "< Plugins >",
cwd = "$HOME/.config/nvim/lua/plugins/",
attach_mappings = function(_, map)
map("i", "<C-t>", my_actions.create_plugin)
map("i", "<C-d>", my_actions.disable_plugin)
map("i", "<C-e>", my_actions.enable_plugin)
return true
end,
}
end
function M.grep_string()
vim.ui.input({ prompt = "Grep for > " }, function(input)
if input == nil then
return
end
require("telescope.builtin").grep_string { search = input }
end)
end
function M.grep_word()
require("telescope.builtin").grep_string { search = vim.fn.expand "<cword>" }
end
function M.find_symbol()
vim.ui.input({ prompt = "Symbol for > " }, function(input)
if input == nil then
return
end
require("telescope.builtin").lsp_workspace_symbols { query = input }
end)
end
function M.my_plugins()
if vim.fn.isdirectory(vim.fn.getenv "HOME" .. "/code/plugins/") == 0 then
vim.notify("Directory ~/code/plugins does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" })
return
end
require("telescope.builtin").find_files {
cwd = "~/code/plugins/",
}
end
function M.scratchs()
require("telescope.builtin").find_files {
prompt_title = "Scratchs",
no_ignore = true,
cwd = "~/.config/nvim/lua/scratchs/",
attach_mappings = function(_, map)
map("i", "<c-t>", my_actions.create_scratch_file)
return true
end,
}
end
function M.projectionist()
return require("telescope").extensions.projectionist.projectionist()
end
function M.laravel_commands()
return require("telescope").extensions.laravel.laravel()
end
function M.api_specs()
if vim.fn.isdirectory "./api-specification" == 0 then
vim.notify("Directory api-specification does not exists", vim.log.levels.WARN, { title = "Telescope Mappings" })
return
end
require("telescope.builtin").git_files {
cwd = "./api-specification",
show_untracked = true,
}
end
function M.worktree()
return require("telescope").extensions.git_worktree.git_worktrees()
end
function M.worktree_create()
return require("telescope").extensions.git_worktree.create_git_worktree()
end
function M.refactor()
return require("telescope").extensions.refactoring.refactors()
end
function M.file_browser_relative()
return M.file_browser { path = "%:p:h" }
end
function M.gateway()
return require("alpha.php.gateway").graphql_definitions {
layout_config = {
horizontal = {
preview_width = function(_, cols, _)
return math.floor(cols * 0.7)
end,
},
},
}
end
function M.file_browser(opts)
opts = opts or {}
opts = {
path = opts.path,
sorting_strategy = "ascending",
scroll_strategy = "cycle",
layout_config = {
prompt_position = "top",
},
attach_mappings = function(_, map)
map("i", "<c-y>", fb_actions.create_from_prompt)
return true
end,
}
return require("telescope").extensions.file_browser.file_browser(opts)
end
return setmetatable({}, {
__index = function(_, k)
reloader()
if M[k] then
return M[k]
else
return require("telescope.builtin")[k]
end
end,
})
|