NvChad Updater | Chadrc Fixes | Cleanup and Formatting | Misc (#288)

* tree-wide: Format files

ugh why do people don't push formatted stuff

* mappings|init: Move init mappings to a function, only call when required | Show err message for init

because mappings.lua is called from multiple places, so there should't be any code that executes without calling a specific function

show error message when something fails in init.lua
makes no sense to not

rearrange plugin functions alphabetically, but keep misc at top

* feat: Do not depend on user config | Fix merging of configs

because it is a user config, so our config shoudn't break even we if dont have it

use our own table merge function

move loading config to a function

use a global variable to store the config, so no need to call the table function everytime

* Add NvChadUpdate command and shortcut for it

map leader+uu to it

summary of what it does:

first ask the user for confirmation and tell that the updater is gonna run git reset --hard in config repo and chadrc will be restored

take backup of chadrc in a lua string and locally in a file with chadrc.bak.(random numbers)

git reset on config dir and git pull

whether success or error, restore the chadrc file

if restore fails, then print backup file path

for more deep understanding, read the comments in utils.lua

* NvChadUpdater: Make update repo and url configurable | Improvr logging
This commit is contained in:
Aki 2021-08-19 12:33:11 +05:30 committed by GitHub
parent 623a2a0d1a
commit 36cb57ecce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 389 additions and 197 deletions

View file

@ -10,7 +10,7 @@ M.term_picker = function(opts)
pickers = require "telescope.pickers"
finders = require "telescope.finders"
previewers = require "telescope.previewers"
make_entry = require "telescope.make_entry"
actions = require "telescope.actions"
action_state = require "telescope.actions.state"
@ -19,26 +19,25 @@ M.term_picker = function(opts)
else
error "Cannot find telescope!"
end
local filter = vim.tbl_filter
local local_utils = require "utils"
-- buffer number and name
local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(bufnr)
local bufnrs = filter(function(b)
local present_type, type = pcall(function()
return vim.api.nvim_buf_get_var(b, "term_type")
end)
if not present_type then
-- let's only terms that we created
return false
end
-- if 1 ~= vim.fn.buflisted(b) then
-- return false
-- end
@ -59,22 +58,22 @@ M.term_picker = function(opts)
return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused
end)
end
local buffers = {}
local default_selection_idx = 1
for _, bufnr in ipairs(bufnrs) do
local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ")
if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then
default_selection_idx = 2
end
local element = {
bufnr = bufnr,
flag = flag,
info = vim.fn.getbufinfo(bufnr)[1],
}
if opts.sort_lastused and (flag == "#" or flag == "%") then
local idx = ((buffers[1] ~= nil and buffers[1].flag == "%") and 2 or 1)
table.insert(buffers, idx, element)
@ -82,12 +81,12 @@ M.term_picker = function(opts)
table.insert(buffers, element)
end
end
if not opts.bufnr_width then
local max_bufnr = math.max(unpack(bufnrs))
opts.bufnr_width = #tostring(max_bufnr)
end
pickers.new(opts, {
prompt_title = "Terminal buffers",
finder = finders.new_table {
@ -103,24 +102,24 @@ M.term_picker = function(opts)
actions.close(prompt_bufnr)
local buf = entry.bufnr
local chad_term, type = pcall(function()
return vim.api.nvim_buf_get_var(buf, "term_type")
end)
return vim.api.nvim_buf_get_var(buf, "term_type")
end)
-- TODO buffer checks/error detection (make sure we do get a buf)
if chad_term then
if type == "wind" then
-- swtich to term buff & show in bufferline
vim.cmd(string.format('b %d | setlocal bl', buf))
vim.cmd(string.format("b %d | setlocal bl", buf))
-- vim.cmd('startinsert') TODO fix this
elseif type == "vert" then
vim.cmd(string.format('vsp #%d', buf))
vim.cmd(string.format("vsp #%d", buf))
-- vim.cmd('startinsert') TODO fix this
elseif type == "hori" then
-- TODO change 15 to a chad config var number
vim.cmd(string.format('15 sp #%d ', buf))
vim.cmd(string.format("15 sp #%d ", buf))
-- vim.cmd('startinsert') TODO fix this
end
end