Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
feat(core): Add DoomNuke command to re-install all plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
connorgmeean committed Oct 8, 2022
1 parent 7d90b56 commit c3f3f03
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lua/doom/core/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ vim.cmd([[command! DoomManual lua require("doom.core.functions").open_docs()]])
-- Set a custom command to create a crash report can be called by using
-- :DoomReport.
vim.cmd([[command! DoomReport lua require("doom.core.functions").create_report(]])

vim.cmd([[command! -nargs=* DoomNuke lua require("doom.core.functions").nuke(<f-args>)]])
31 changes: 29 additions & 2 deletions lua/doom/core/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ end
-- Set the indent and tab related numbers.
-- Negative numbers mean tabstop -- Really though? Tabs?
functions.set_indent = function()
local indent =
tonumber(vim.fn.input("Set indent (>0 uses spaces, <0 uses tabs, 0 uses vim defaults): "))
local indent = tonumber(
vim.fn.input("Set indent (>0 uses spaces, <0 uses tabs, 0 uses vim defaults): ")
)
if not indent then
indent = -8
end
Expand Down Expand Up @@ -251,4 +252,30 @@ functions.sugar_folds = function()
return string.format("%s ... (%d lines)", start_line, vim.v.foldend - vim.v.foldstart + 1)
end

--- Nukes the doom install config, causes a fresh install on next boot.
---@param target string Options of what to nuke
functions.nuke = function(target)
if target == nil or #target == 0 then
vim.notify(
"Warning, this command deletes packer caches and causes a re-install of doom-nvim on next launch.\n\n :DoomNuke `plugins`|`cache`|`all`. \n\t `cache` - Clear packer_compiled.lua\n\t `plugins` - Clear all installed plugins\n\t `all` - Delete all of the above."
)
return
end

local log = require("doom.utils.logging")
-- Delete packer compiled
if target == "all" or target == "cache" then
os.remove(system.doom_compile_path)
log.info("DoomNuke: Deleting packer compiled.")
end

if target == "all" or target == "plugins" then
-- Delete all plugins
local util = require("packer.util")
local plugin_dir = util.join_paths(vim.fn.stdpath("data"), "site", "pack")
fs.rm_dir(plugin_dir)
log.info("DoomNuke: Deleting packer plugins. Doom-nvim will re-install on next launch.")
end
end

return functions
56 changes: 56 additions & 0 deletions lua/doom/utils/fs.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
local luv = vim.loop
local fs = {}

if jit ~= nil then
fs.is_windows = jit.os == 'Windows'
else
fs.is_windows = package.config:sub(1, 1) == '\\'
end

if fs.is_windows and vim.o.shellslash then
fs.use_shellslash = true
else
fs.use_shallslash = false
end

fs.get_seperator = function()
if fs.is_windows and not fs.use_shellslash then
return '\\'
end
return '/'
end

--- Joins a number of strings into a valid path
---@vararg string[] String segments to convert to file system path
fs.join_paths = function(...)
return table.concat({ ... }, fs.get_seperator())
end

--- Check if the given file exists
--- @param path string The path of the file
--- @return boolean
Expand Down Expand Up @@ -41,4 +67,34 @@ fs.write_file = function(path, content, mode)
end)
end

fs.rm_dir = function(path)
local handle = luv.fs_scandir(path)

if type(handle) == "string" then
return fs.notify.error(handle)
end

while true do
local name, t = luv.fs_scandir_next(handle)
if not name then
break
end

local new_cwd = fs.join_paths( path, name )
if t == "directory" then
local success = fs.rm_dir(new_cwd)
if not success then
return false
end
else
local success = luv.fs_unlink(new_cwd)
if not success then
return false
end
end
end

return luv.fs_rmdir(path)
end

return fs

0 comments on commit c3f3f03

Please sign in to comment.