@@ -141,8 +141,23 @@ function P.update_neovim(opts)
141141
142142 local build_command = " cd " .. source_dir .. " && make CMAKE_BUILD_TYPE=" .. build_type .. " && sudo make install"
143143
144+ local update_command = git_commands .. " && " .. build_command
145+
144146 -- Use the open_floating_terminal from the 'utils' module
145- utils .open_floating_terminal (git_commands .. " && " .. build_command , " neovim_updater_term.updating" , false , true )
147+ utils .open_floating_terminal ({
148+ command = update_command ,
149+ filetype = " neovim_updater_term.updating" ,
150+ ispreupdate = false ,
151+ autoclose = true ,
152+ callback = function (results )
153+ if results .result_code ~= 0 then
154+ utils .notify (" Neovim update failed with error code: " .. results .result_code , vim .log .levels .ERROR )
155+ else
156+ utils .notify (" Neovim update complete!" , vim .log .levels .INFO )
157+ utils .notify (" Please restart Neovim for the changes to take effect." , vim .log .levels .INFO )
158+ end
159+ end ,
160+ })
146161
147162 -- Go to insert mode
148163 vim .cmd (" startinsert" )
154169--- Remove the Neovim source directory or a custom one.
155170--- @function P.remove_source_dir
156171--- @param opts table | nil Optional table for ' source_dir'
157- --- @return boolean success True if the directory was successfully removed , false otherwise
172+ --- @return boolean | nil success True if the directory was successfully removed
173+ --- False if the directory does not exist or an error occurred
174+ --- nil if the function is delayed until the terminal is closed
175+ --- Check the U.defered_value variable for the result
158176function P .remove_source_dir (opts )
159177 opts = opts or {}
160178 local source_dir = opts .source_dir ~= " " and opts .source_dir or P .default_config .source_dir
@@ -172,12 +190,47 @@ function P.remove_source_dir(opts)
172190 if not err then
173191 err = " Unknown error"
174192 end
175- utils .notify (
176- " Error removing Neovim source directory: " .. source_dir .. " \n " .. err ,
177- vim .log .levels .ERROR
178- )
179193 utils .notify (" Source directory removal failed with vim.fs.rm" , vim .log .levels .DEBUG )
180- return false
194+
195+ -- Define callback function for checking rm
196+ local function check_rm ()
197+ -- Check if the source directory still exists
198+ if not utils .directory_exists (source_dir ) then
199+ utils .notify (
200+ " Successfully removed Neovim source directory: " .. source_dir ,
201+ vim .log .levels .INFO
202+ )
203+ return true
204+ end
205+ utils .notify (" Failed to remove Neovim source directory: " .. source_dir , vim .log .levels .ERROR )
206+ return false
207+ end
208+
209+ -- Attempt to remove with elevated privileges
210+ local rm_msg = " echo Attempting to remove source directory with elevated privileges.\n "
211+ .. " echo Please authorize sudo and press enter.\n "
212+ local privileged_rm = rm_msg .. " sudo rm -rf " .. source_dir
213+ utils .open_floating_terminal ({
214+ command = privileged_rm ,
215+ filetype = " neovim_updater_term.privileged_rm" ,
216+ ispreupdate = false ,
217+ autoclose = true ,
218+ callback = function (results )
219+ if results .result_code == 0 then
220+ -- Double-check the results
221+ check_rm ()
222+ else
223+ utils .notify (
224+ " Failed to remove Neovim source directory: " .. source_dir ,
225+ vim .log .levels .ERROR
226+ )
227+ end
228+ end ,
229+ })
230+ -- Go to insert mode
231+ vim .cmd (" startinsert" )
232+
233+ return nil
181234 end
182235 end
183236 -- Fallback to vim.fn.delete if vim.fs.rm is not available
@@ -211,23 +264,40 @@ function P.generate_source_dir(opts)
211264 local repo = " https://github.com/neovim/neovim.git"
212265 local branch = opts .branch ~= " " and opts .branch or P .default_config .branch
213266
214- -- Build the command to fetch the latest changes from the remote repository
215- local fetch_command = (" cd ~ && git clone %s %s" ):format (repo , source_dir )
216-
217- -- Checkout the branch
218- local checkout_command = " cd " .. source_dir .. " && git checkout " .. branch
219-
220- -- Combine commands
221- local complete_command = fetch_command .. " && " .. checkout_command
222-
223- -- Notify the user that the clone is starting
224- utils .notify (" Cloning Neovim source..." , vim .log .levels .INFO )
225-
226- -- Open a terminal window
227- utils .open_floating_terminal (complete_command , " neovim_updater_term.cloning" , false , false )
267+ if not utils .directory_exists (source_dir ) then
268+ -- Build the command to fetch the latest changes from the remote repository
269+ local fetch_command = (" cd ~ && git clone %s %s" ):format (repo , source_dir )
270+
271+ -- Checkout the branch
272+ local checkout_command = " cd " .. source_dir .. " && git checkout " .. branch
273+
274+ -- Combine commands
275+ local complete_command = fetch_command .. " && " .. checkout_command
276+
277+ -- Notify the user that the clone is starting
278+ utils .notify (" Cloning Neovim source..." , vim .log .levels .INFO )
279+
280+ -- Open a terminal window
281+ utils .open_floating_terminal ({
282+ command = complete_command ,
283+ filetype = " neovim_updater_term.cloning" ,
284+ ispreupdate = false ,
285+ autoclose = true ,
286+ callback = function (results )
287+ if results .result_code == 0 then
288+ utils .notify (" Neovim source cloned successfully" , vim .log .levels .INFO )
289+ else
290+ utils .notify (" Failed to clone Neovim source: " .. results .result_code , vim .log .levels .ERROR )
291+ end
292+ end ,
293+ })
228294
229- -- Set the update count to "0"
230- P .last_status .count = " 0"
295+ -- Set the update count to "0"
296+ P .last_status .count = " 0"
297+ else
298+ -- Notify the user that the source directory already exists
299+ utils .notify (" Neovim source directory already exists: " .. source_dir , vim .log .levels .WARN )
300+ end
231301
232302 -- Return the source directory
233303 return source_dir
354424--- @param short ? boolean Optional. Whether to show a short commit list. Only used if ` isupdate` is a boolean.
355425function P .show_new_commits (isupdate , short )
356426 -- If the first argument is a table, treat it as an options table.
427+ local doupdate = false
357428 if type (isupdate ) == " table" then
358429 local opts = isupdate
359- isupdate = opts .isupdate
430+ doupdate = opts .isupdate
360431 short = opts .short
361432 end
362433 -- Define the path to the Neovim source directory
@@ -409,8 +480,15 @@ function P.show_new_commits(isupdate, short)
409480 utils .open_floating_terminal ({
410481 command = term_command ,
411482 filetype = " neovim_updater_term.changes" ,
412- ispreupdate = isupdate ,
483+ ispreupdate = false ,
413484 autoclose = false ,
485+ callback = function ()
486+ if doupdate then
487+ utils .ConfirmPrompt (" Perform Neovim update?" , function ()
488+ P .update_neovim ()
489+ end )
490+ end
491+ end ,
414492 })
415493 else
416494 utils .notify (" No new Neovim commits." , vim .log .levels .INFO )
0 commit comments