2828local toggle_forced_deletion = function ()
2929 -- redraw otherwise the message is not displayed when in insert mode
3030 if force_next_deletion then
31- print (' The next deletion will not be forced' )
32- vim .fn .execute (' redraw' )
31+ print (" The next deletion will not be forced" )
32+ vim .fn .execute (" redraw" )
3333 else
34- print (' The next deletion will be forced' )
35- vim .fn .execute (' redraw' )
34+ print (" The next deletion will be forced" )
35+ vim .fn .execute (" redraw" )
3636 force_next_deletion = true
3737 end
3838end
@@ -76,15 +76,14 @@ local delete_worktree = function(prompt_bufnr)
7676 local worktree_path = get_worktree_path (prompt_bufnr )
7777 actions .close (prompt_bufnr )
7878 if worktree_path ~= nil then
79- git_worktree .delete_worktree (worktree_path , force_next_deletion , {
80- on_failure = delete_failure_handler ,
81- on_success = delete_success_handler
82- })
79+ git_worktree .delete_worktree (worktree_path , force_next_deletion , {
80+ on_failure = delete_failure_handler ,
81+ on_success = delete_success_handler ,
82+ })
8383 end
8484end
8585
8686local create_input_prompt = function (cb )
87-
8887 --[[
8988 local window = Window.centered({
9089 width = 30,
@@ -112,27 +111,25 @@ end
112111local create_worktree = function (opts )
113112 opts = opts or {}
114113 opts .attach_mappings = function ()
115- actions .select_default :replace (
116- function (prompt_bufnr , _ )
117- local selected_entry = action_state .get_selected_entry ()
118- local current_line = action_state .get_current_line ()
114+ actions .select_default :replace (function (prompt_bufnr , _ )
115+ local selected_entry = action_state .get_selected_entry ()
116+ local current_line = action_state .get_current_line ()
119117
120- actions .close (prompt_bufnr )
118+ actions .close (prompt_bufnr )
121119
122- local branch = selected_entry ~= nil and
123- selected_entry .value or current_line
120+ local branch = selected_entry ~= nil and selected_entry .value or current_line
124121
125- if branch == nil then
126- return
127- end
122+ if branch == nil then
123+ return
124+ end
128125
129- create_input_prompt (function (name )
130- if name == " " then
131- name = branch
132- end
133- git_worktree .create_worktree (name , branch )
134- end )
126+ create_input_prompt (function (name )
127+ if name == " " then
128+ name = branch
129+ end
130+ git_worktree .create_worktree (name , branch )
135131 end )
132+ end )
136133
137134 -- do we need to replace other default maps?
138135
@@ -143,12 +140,12 @@ end
143140
144141local telescope_git_worktree = function (opts )
145142 opts = opts or {}
146- local output = utils .get_os_command_output ({" git" , " worktree" , " list" })
143+ local output = utils .get_os_command_output ({ " git" , " worktree" , " list" })
147144 local results = {}
148145 local widths = {
149146 path = 0 ,
150147 sha = 0 ,
151- branch = 0
148+ branch = 0 ,
152149 }
153150
154151 local parse_line = function (line )
@@ -162,7 +159,7 @@ local telescope_git_worktree = function(opts)
162159 if entry .sha ~= " (bare)" then
163160 local index = # results + 1
164161 for key , val in pairs (widths ) do
165- if key == ' path' then
162+ if key == " path" then
166163 local new_path = utils .transform_path (opts , entry [key ])
167164 local path_len = strings .strdisplaywidth (new_path or " " )
168165 widths [key ] = math.max (val , path_len )
@@ -183,53 +180,55 @@ local telescope_git_worktree = function(opts)
183180 return
184181 end
185182
186- local displayer = require (" telescope.pickers.entry_display" ).create {
183+ local displayer = require (" telescope.pickers.entry_display" ).create ( {
187184 separator = " " ,
188185 items = {
189186 { width = widths .branch },
190187 { width = widths .path },
191188 { width = widths .sha },
192189 },
193- }
190+ })
194191
195192 local make_display = function (entry )
196- return displayer {
193+ local path , _ = utils .transform_path (opts , entry .path )
194+ return displayer ({
197195 { entry .branch , " TelescopeResultsIdentifier" },
198- { utils . transform_path ( opts , entry . path ) },
196+ { path },
199197 { entry .sha },
200- }
198+ })
201199 end
202200
203- pickers .new (opts or {}, {
204- prompt_title = " Git Worktrees" ,
205- finder = finders .new_table {
206- results = results ,
207- entry_maker = function (entry )
208- entry .value = entry .branch
209- entry .ordinal = entry .branch
210- entry .display = make_display
211- return entry
201+ pickers
202+ .new (opts or {}, {
203+ prompt_title = " Git Worktrees" ,
204+ finder = finders .new_table ({
205+ results = results ,
206+ entry_maker = function (entry )
207+ entry .value = entry .branch
208+ entry .ordinal = entry .branch
209+ entry .display = make_display
210+ return entry
211+ end ,
212+ }),
213+ sorter = conf .generic_sorter (opts ),
214+ attach_mappings = function (_ , map )
215+ action_set .select :replace (switch_worktree )
216+
217+ map (" i" , " <c-d>" , delete_worktree )
218+ map (" n" , " <c-d>" , delete_worktree )
219+ map (" i" , " <c-f>" , toggle_forced_deletion )
220+ map (" n" , " <c-f>" , toggle_forced_deletion )
221+
222+ return true
212223 end ,
213- },
214- sorter = conf .generic_sorter (opts ),
215- attach_mappings = function (_ , map )
216- action_set .select :replace (switch_worktree )
217-
218- map (" i" , " <c-d>" , delete_worktree )
219- map (" n" , " <c-d>" , delete_worktree )
220- map (" i" , " <c-f>" , toggle_forced_deletion )
221- map (" n" , " <c-f>" , toggle_forced_deletion )
222-
223- return true
224- end
225- }):find ()
224+ })
225+ :find ()
226226end
227227
228- return require (" telescope" ).register_extension (
229- {
230- exports = {
231- git_worktree = telescope_git_worktree ,
232- git_worktrees = telescope_git_worktree ,
233- create_git_worktree = create_worktree
234- }
235- })
228+ return require (" telescope" ).register_extension ({
229+ exports = {
230+ git_worktree = telescope_git_worktree ,
231+ git_worktrees = telescope_git_worktree ,
232+ create_git_worktree = create_worktree ,
233+ },
234+ })
0 commit comments