mirror of
https://github.com/Keyitdev/dotfiles.git
synced 2026-09-24 01:52:09 +00:00
New version: created v3
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
local is_available = astronvim.is_available
|
||||
local cmd = vim.api.nvim_create_autocmd
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local create_command = vim.api.nvim_create_user_command
|
||||
|
||||
augroup("highlighturl", { clear = true })
|
||||
cmd({ "VimEnter", "FileType", "BufEnter", "WinEnter" }, {
|
||||
desc = "URL Highlighting",
|
||||
group = "highlighturl",
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
astronvim.set_url_match()
|
||||
end,
|
||||
})
|
||||
|
||||
if is_available "alpha-nvim" then
|
||||
augroup("alpha_settings", { clear = true })
|
||||
if is_available "bufferline.nvim" then
|
||||
cmd("FileType", {
|
||||
desc = "Disable tabline for alpha",
|
||||
group = "alpha_settings",
|
||||
pattern = "alpha",
|
||||
callback = function()
|
||||
local prev_showtabline = vim.opt.showtabline
|
||||
vim.opt.showtabline = 0
|
||||
cmd("BufUnload", {
|
||||
pattern = "<buffer>",
|
||||
callback = function()
|
||||
vim.opt.showtabline = prev_showtabline
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
cmd("FileType", {
|
||||
desc = "Disable statusline for alpha",
|
||||
group = "alpha_settings",
|
||||
pattern = "alpha",
|
||||
callback = function()
|
||||
local prev_status = vim.opt.laststatus
|
||||
vim.opt.laststatus = 0
|
||||
cmd("BufUnload", {
|
||||
pattern = "<buffer>",
|
||||
callback = function()
|
||||
vim.opt.laststatus = prev_status
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
cmd("VimEnter", {
|
||||
desc = "Start Alpha when vim is opened with no arguments",
|
||||
group = "alpha_settings",
|
||||
callback = function()
|
||||
-- optimized start check from https://github.com/goolord/alpha-nvim
|
||||
local alpha_avail, alpha = pcall(require, "alpha")
|
||||
if alpha_avail then
|
||||
local should_skip = false
|
||||
if vim.fn.argc() > 0 or vim.fn.line2byte "$" ~= -1 or not vim.o.modifiable then
|
||||
should_skip = true
|
||||
else
|
||||
for _, arg in pairs(vim.v.argv) do
|
||||
if arg == "-b" or arg == "-c" or vim.startswith(arg, "+") or arg == "-S" then
|
||||
should_skip = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not should_skip then
|
||||
alpha.start(true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if is_available "neo-tree.nvim" then
|
||||
augroup("neotree_start", { clear = true })
|
||||
cmd("BufEnter", {
|
||||
desc = "Open Neo-Tree on startup with directory",
|
||||
group = "neotree_start",
|
||||
callback = function()
|
||||
local stats = vim.loop.fs_stat(vim.api.nvim_buf_get_name(0))
|
||||
if stats and stats.type == "directory" then
|
||||
require("neo-tree.setup.netrw").hijack()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if is_available "feline.nvim" then
|
||||
augroup("feline_setup", { clear = true })
|
||||
cmd("ColorScheme", {
|
||||
desc = "Reload feline on colorscheme change",
|
||||
group = "feline_setup",
|
||||
callback = function()
|
||||
package.loaded["configs.feline"] = nil
|
||||
require "configs.feline"
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
create_command("AstroUpdate", astronvim.updater.update, { desc = "Update AstroNvim" })
|
||||
create_command("AstroVersion", astronvim.updater.version, { desc = "Check AstroNvim Version" })
|
||||
create_command("ToggleHighlightURL", astronvim.toggle_url_match, { desc = "Toggle URL Highlights" })
|
||||
@@ -0,0 +1,420 @@
|
||||
local is_available = astronvim.is_available
|
||||
|
||||
local maps = { n = {}, v = {}, t = {}, [""] = {} }
|
||||
|
||||
maps[""]["<Space>"] = "<Nop>"
|
||||
|
||||
-- Normal --
|
||||
-- Standard Operations
|
||||
maps.n["<leader>w"] = { "<cmd>w<cr>", desc = "Save" }
|
||||
maps.n["<leader>q"] = { "<cmd>q<cr>", desc = "Quit" }
|
||||
maps.n["<leader>h"] = { "<cmd>nohlsearch<cr>", desc = "No Highlight" }
|
||||
maps.n["<leader>u"] = {
|
||||
function()
|
||||
astronvim.toggle_url_match()
|
||||
end,
|
||||
desc = "Toggle URL Highlights",
|
||||
}
|
||||
maps.n["<leader>fn"] = { "<cmd>enew<cr>", desc = "New File" }
|
||||
maps.n["gx"] = {
|
||||
function()
|
||||
astronvim.url_opener()
|
||||
end,
|
||||
desc = "Open the file under cursor with system app",
|
||||
}
|
||||
maps.n["<C-s>"] = { "<cmd>w!<cr>", desc = "Force write" }
|
||||
maps.n["<C-q>"] = { "<cmd>q!<cr>", desc = "Force quit" }
|
||||
maps.n["Q"] = "<Nop>"
|
||||
|
||||
-- Packer
|
||||
maps.n["<leader>pc"] = { "<cmd>PackerCompile<cr>", desc = "Packer Compile" }
|
||||
maps.n["<leader>pi"] = { "<cmd>PackerInstall<cr>", desc = "Packer Install" }
|
||||
maps.n["<leader>ps"] = { "<cmd>PackerSync<cr>", desc = "Packer Sync" }
|
||||
maps.n["<leader>pS"] = { "<cmd>PackerStatus<cr>", desc = "Packer Status" }
|
||||
maps.n["<leader>pu"] = { "<cmd>PackerUpdate<cr>", desc = "Packer Update" }
|
||||
|
||||
-- Alpha
|
||||
if is_available "alpha-nvim" then
|
||||
maps.n["<leader>d"] = { "<cmd>Alpha<cr>", desc = "Alpha Dashboard" }
|
||||
end
|
||||
|
||||
-- Bufdelete
|
||||
if is_available "bufdelete.nvim" then
|
||||
maps.n["<leader>c"] = { "<cmd>Bdelete<cr>", desc = "Close buffer" }
|
||||
else
|
||||
maps.n["<leader>c"] = { "<cmd>bdelete<cr>", desc = "Close buffer" }
|
||||
end
|
||||
|
||||
-- Navigate buffers
|
||||
if is_available "bufferline.nvim" then
|
||||
maps.n["<S-l>"] = { "<cmd>BufferLineCycleNext<cr>", desc = "Next buffer tab" }
|
||||
maps.n["<S-h>"] = { "<cmd>BufferLineCyclePrev<cr>", desc = "Previous buffer tab" }
|
||||
maps.n[">b"] = { "<cmd>BufferLineMoveNext<cr>", desc = "Move buffer tab right" }
|
||||
maps.n["<b"] = { "<cmd>BufferLineMovePrev<cr>", desc = "Move buffer tab left" }
|
||||
else
|
||||
maps.n["<S-l>"] = { "<cmd>bnext<cr>", desc = "Next buffer" }
|
||||
maps.n["<S-h>"] = { "<cmd>bprevious<cr>", desc = "Previous buffer" }
|
||||
end
|
||||
|
||||
-- Comment
|
||||
if is_available "Comment.nvim" then
|
||||
maps.n["<leader>/"] = {
|
||||
function()
|
||||
require("Comment.api").toggle_current_linewise()
|
||||
end,
|
||||
desc = "Comment line",
|
||||
}
|
||||
maps.v["<leader>/"] = {
|
||||
"<esc><cmd>lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<cr>",
|
||||
desc = "Toggle comment line",
|
||||
}
|
||||
end
|
||||
|
||||
-- GitSigns
|
||||
if is_available "gitsigns.nvim" then
|
||||
maps.n["<leader>gj"] = {
|
||||
function()
|
||||
require("gitsigns").next_hunk()
|
||||
end,
|
||||
desc = "Next git hunk",
|
||||
}
|
||||
maps.n["<leader>gk"] = {
|
||||
function()
|
||||
require("gitsigns").prev_hunk()
|
||||
end,
|
||||
desc = "Previous git hunk",
|
||||
}
|
||||
maps.n["<leader>gl"] = {
|
||||
function()
|
||||
require("gitsigns").blame_line()
|
||||
end,
|
||||
desc = "View git blame",
|
||||
}
|
||||
maps.n["<leader>gp"] = {
|
||||
function()
|
||||
require("gitsigns").preview_hunk()
|
||||
end,
|
||||
desc = "Preview git hunk",
|
||||
}
|
||||
maps.n["<leader>gh"] = {
|
||||
function()
|
||||
require("gitsigns").reset_hunk()
|
||||
end,
|
||||
desc = "Reset git hunk",
|
||||
}
|
||||
maps.n["<leader>gr"] = {
|
||||
function()
|
||||
require("gitsigns").reset_buffer()
|
||||
end,
|
||||
desc = "Reset git buffer",
|
||||
}
|
||||
maps.n["<leader>gs"] = {
|
||||
function()
|
||||
require("gitsigns").stage_hunk()
|
||||
end,
|
||||
desc = "Stage git hunk",
|
||||
}
|
||||
maps.n["<leader>gu"] = {
|
||||
function()
|
||||
require("gitsigns").undo_stage_hunk()
|
||||
end,
|
||||
desc = "Unstage git hunk",
|
||||
}
|
||||
maps.n["<leader>gd"] = {
|
||||
function()
|
||||
require("gitsigns").diffthis()
|
||||
end,
|
||||
desc = "View git diff",
|
||||
}
|
||||
end
|
||||
|
||||
-- NeoTree
|
||||
if is_available "neo-tree.nvim" then
|
||||
maps.n["<leader>e"] = { "<cmd>Neotree toggle<cr>", desc = "Toggle Explorer" }
|
||||
maps.n["<leader>o"] = { "<cmd>Neotree focus<cr>", desc = "Focus Explorer" }
|
||||
end
|
||||
|
||||
-- Session Manager
|
||||
if is_available "neovim-session-manager" then
|
||||
maps.n["<leader>Sl"] = { "<cmd>SessionManager! load_last_session<cr>", desc = "Load last session" }
|
||||
maps.n["<leader>Ss"] = { "<cmd>SessionManager! save_current_session<cr>", desc = "Save this session" }
|
||||
maps.n["<leader>Sd"] = { "<cmd>SessionManager! delete_session<cr>", desc = "Delete session" }
|
||||
maps.n["<leader>Sf"] = { "<cmd>SessionManager! load_session<cr>", desc = "Search sessions" }
|
||||
maps.n["<leader>S."] = {
|
||||
"<cmd>SessionManager! load_current_dir_session<cr>",
|
||||
desc = "Load current directory session",
|
||||
}
|
||||
end
|
||||
|
||||
-- LSP Installer
|
||||
if is_available "nvim-lsp-installer" then
|
||||
maps.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" }
|
||||
maps.n["<leader>lI"] = { "<cmd>LspInstallInfo<cr>", desc = "LSP installer" }
|
||||
end
|
||||
|
||||
-- Smart Splits
|
||||
if is_available "smart-splits.nvim" then
|
||||
-- Better window navigation
|
||||
maps.n["<C-h>"] = {
|
||||
function()
|
||||
require("smart-splits").move_cursor_left()
|
||||
end,
|
||||
desc = "Move to left split",
|
||||
}
|
||||
maps.n["<C-j>"] = {
|
||||
function()
|
||||
require("smart-splits").move_cursor_down()
|
||||
end,
|
||||
desc = "Move to below split",
|
||||
}
|
||||
maps.n["<C-k>"] = {
|
||||
function()
|
||||
require("smart-splits").move_cursor_up()
|
||||
end,
|
||||
desc = "Move to above split",
|
||||
}
|
||||
maps.n["<C-l>"] = {
|
||||
function()
|
||||
require("smart-splits").move_cursor_right()
|
||||
end,
|
||||
desc = "Move to right split",
|
||||
}
|
||||
|
||||
-- Resize with arrows
|
||||
maps.n["<C-Up>"] = {
|
||||
function()
|
||||
require("smart-splits").resize_up()
|
||||
end,
|
||||
desc = "Resize split up",
|
||||
}
|
||||
maps.n["<C-Down>"] = {
|
||||
function()
|
||||
require("smart-splits").resize_down()
|
||||
end,
|
||||
desc = "Resize split down",
|
||||
}
|
||||
maps.n["<C-Left>"] = {
|
||||
function()
|
||||
require("smart-splits").resize_left()
|
||||
end,
|
||||
desc = "Resize split left",
|
||||
}
|
||||
maps.n["<C-Right>"] = {
|
||||
function()
|
||||
require("smart-splits").resize_right()
|
||||
end,
|
||||
desc = "Resize split right",
|
||||
}
|
||||
else
|
||||
maps.n["<C-h>"] = { "<C-w>h", desc = "Move to left split" }
|
||||
maps.n["<C-j>"] = { "<C-w>j", desc = "Move to below split" }
|
||||
maps.n["<C-k>"] = { "<C-w>k", desc = "Move to above split" }
|
||||
maps.n["<C-l>"] = { "<C-w>l", desc = "Move to right split" }
|
||||
maps.n["<C-Up>"] = { "<cmd>resize -2<CR>", desc = "Resize split up" }
|
||||
maps.n["<C-Down>"] = { "<cmd>resize +2<CR>", desc = "Resize split down" }
|
||||
maps.n["<C-Left>"] = { "<cmd>vertical resize -2<CR>", desc = "Resize split left" }
|
||||
maps.n["<C-Right>"] = { "<cmd>vertical resize +2<CR>", desc = "Resize split right" }
|
||||
end
|
||||
|
||||
-- SymbolsOutline
|
||||
if is_available "aerial.nvim" then
|
||||
maps.n["<leader>lS"] = { "<cmd>AerialToggle<cr>", desc = "Symbols outline" }
|
||||
end
|
||||
|
||||
-- Telescope
|
||||
if is_available "telescope.nvim" then
|
||||
maps.n["<leader>fw"] = {
|
||||
function()
|
||||
require("telescope.builtin").live_grep()
|
||||
end,
|
||||
desc = "Search words",
|
||||
}
|
||||
maps.n["<leader>fW"] = {
|
||||
function()
|
||||
require("telescope.builtin").live_grep {
|
||||
additional_args = function(args)
|
||||
return vim.list_extend(args, { "--hidden", "--no-ignore" })
|
||||
end,
|
||||
}
|
||||
end,
|
||||
desc = "Search words in all files",
|
||||
}
|
||||
maps.n["<leader>gt"] = {
|
||||
function()
|
||||
require("telescope.builtin").git_status()
|
||||
end,
|
||||
desc = "Git status",
|
||||
}
|
||||
maps.n["<leader>gb"] = {
|
||||
function()
|
||||
require("telescope.builtin").git_branches()
|
||||
end,
|
||||
desc = "Git branches",
|
||||
}
|
||||
maps.n["<leader>gc"] = {
|
||||
function()
|
||||
require("telescope.builtin").git_commits()
|
||||
end,
|
||||
desc = "Git commits",
|
||||
}
|
||||
maps.n["<leader>ff"] = {
|
||||
function()
|
||||
require("telescope.builtin").find_files()
|
||||
end,
|
||||
desc = "Search files",
|
||||
}
|
||||
maps.n["<leader>fF"] = {
|
||||
function()
|
||||
require("telescope.builtin").find_files { hidden = true, no_ignore = true }
|
||||
end,
|
||||
desc = "Search all files",
|
||||
}
|
||||
maps.n["<leader>fb"] = {
|
||||
function()
|
||||
require("telescope.builtin").buffers()
|
||||
end,
|
||||
desc = "Search buffers",
|
||||
}
|
||||
maps.n["<leader>fh"] = {
|
||||
function()
|
||||
require("telescope.builtin").help_tags()
|
||||
end,
|
||||
desc = "Search help",
|
||||
}
|
||||
maps.n["<leader>fm"] = {
|
||||
function()
|
||||
require("telescope.builtin").marks()
|
||||
end,
|
||||
desc = "Search marks",
|
||||
}
|
||||
maps.n["<leader>fo"] = {
|
||||
function()
|
||||
require("telescope.builtin").oldfiles()
|
||||
end,
|
||||
desc = "Search history",
|
||||
}
|
||||
maps.n["<leader>sb"] = {
|
||||
function()
|
||||
require("telescope.builtin").git_branches()
|
||||
end,
|
||||
desc = "Git branches",
|
||||
}
|
||||
maps.n["<leader>sh"] = {
|
||||
function()
|
||||
require("telescope.builtin").help_tags()
|
||||
end,
|
||||
desc = "Search help",
|
||||
}
|
||||
maps.n["<leader>sm"] = {
|
||||
function()
|
||||
require("telescope.builtin").man_pages()
|
||||
end,
|
||||
desc = "Search man",
|
||||
}
|
||||
maps.n["<leader>sn"] = {
|
||||
function()
|
||||
require("telescope").extensions.notify.notify()
|
||||
end,
|
||||
desc = "Search notifications",
|
||||
}
|
||||
maps.n["<leader>sr"] = {
|
||||
function()
|
||||
require("telescope.builtin").registers()
|
||||
end,
|
||||
desc = "Search registers",
|
||||
}
|
||||
maps.n["<leader>sk"] = {
|
||||
function()
|
||||
require("telescope.builtin").keymaps()
|
||||
end,
|
||||
desc = "Search keymaps",
|
||||
}
|
||||
maps.n["<leader>sc"] = {
|
||||
function()
|
||||
require("telescope.builtin").commands()
|
||||
end,
|
||||
desc = "Search commands",
|
||||
}
|
||||
maps.n["<leader>ls"] = {
|
||||
function()
|
||||
local aerial_avail, _ = pcall(require, "aerial")
|
||||
if aerial_avail then
|
||||
require("telescope").extensions.aerial.aerial()
|
||||
else
|
||||
require("telescope.builtin").lsp_document_symbols()
|
||||
end
|
||||
end,
|
||||
desc = "Search symbols",
|
||||
}
|
||||
maps.n["<leader>lR"] = {
|
||||
function()
|
||||
require("telescope.builtin").lsp_references()
|
||||
end,
|
||||
desc = "Search references",
|
||||
}
|
||||
maps.n["<leader>lD"] = {
|
||||
function()
|
||||
require("telescope.builtin").diagnostics()
|
||||
end,
|
||||
desc = "Search diagnostics",
|
||||
}
|
||||
end
|
||||
|
||||
-- Terminal
|
||||
if is_available "toggleterm.nvim" then
|
||||
local toggle_term_cmd = astronvim.toggle_term_cmd
|
||||
maps.n["<C-\\>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
|
||||
maps.n["<leader>gg"] = {
|
||||
function()
|
||||
toggle_term_cmd "lazygit"
|
||||
end,
|
||||
desc = "ToggleTerm lazygit",
|
||||
}
|
||||
maps.n["<leader>tn"] = {
|
||||
function()
|
||||
toggle_term_cmd "node"
|
||||
end,
|
||||
desc = "ToggleTerm node",
|
||||
}
|
||||
maps.n["<leader>tu"] = {
|
||||
function()
|
||||
toggle_term_cmd "ncdu"
|
||||
end,
|
||||
desc = "ToggleTerm NCDU",
|
||||
}
|
||||
maps.n["<leader>tt"] = {
|
||||
function()
|
||||
toggle_term_cmd "htop"
|
||||
end,
|
||||
desc = "ToggleTerm htop",
|
||||
}
|
||||
maps.n["<leader>tp"] = {
|
||||
function()
|
||||
toggle_term_cmd "python"
|
||||
end,
|
||||
desc = "ToggleTerm python",
|
||||
}
|
||||
maps.n["<leader>tl"] = {
|
||||
function()
|
||||
toggle_term_cmd "lazygit"
|
||||
end,
|
||||
desc = "ToggleTerm lazygit",
|
||||
}
|
||||
maps.n["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" }
|
||||
maps.n["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
|
||||
maps.n["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" }
|
||||
end
|
||||
|
||||
-- Stay in indent mode
|
||||
maps.v["<"] = { "<gv", desc = "unindent line" }
|
||||
maps.v[">"] = { ">gv", desc = "indent line" }
|
||||
|
||||
-- Improved Terminal Mappings
|
||||
maps.t["<esc>"] = { "<C-\\><C-n>", desc = "Terminal normal mode" }
|
||||
maps.t["jk"] = { "<C-\\><C-n>", desc = "Terminal normal mode" }
|
||||
maps.t["<C-h>"] = { "<c-\\><c-n><c-w>h", desc = "Terminal left window navigation" }
|
||||
maps.t["<C-j>"] = { "<c-\\><c-n><c-w>j", desc = "Terminal down window navigation" }
|
||||
maps.t["<C-k>"] = { "<c-\\><c-n><c-w>k", desc = "Terminal up window navigation" }
|
||||
maps.t["<C-l>"] = { "<c-\\><c-n><c-w>l", desc = "Terminal right window naviation" }
|
||||
|
||||
astronvim.set_mappings(astronvim.user_plugin_opts("mappings", maps))
|
||||
@@ -0,0 +1,67 @@
|
||||
astronvim.vim_opts(astronvim.user_plugin_opts("options", {
|
||||
opt = {
|
||||
backspace = vim.opt.backspace + { "nostop" }, -- Don't stop backspace at insert
|
||||
clipboard = "unnamedplus", -- Connection to the system clipboard
|
||||
completeopt = { "menuone", "noselect" }, -- Options for insert mode completion
|
||||
copyindent = true, -- Copy the previous indentation on autoindenting
|
||||
cursorline = true, -- Highlight the text line of the cursor
|
||||
expandtab = true, -- Enable the use of space in tab
|
||||
fileencoding = "utf-8", -- File content encoding for the buffer
|
||||
fillchars = { eob = " " }, -- Disable `~` on nonexistent lines
|
||||
history = 100, -- Number of commands to remember in a history table
|
||||
ignorecase = true, -- Case insensitive searching
|
||||
laststatus = 3, -- globalstatus
|
||||
lazyredraw = true, -- lazily redraw screen
|
||||
mouse = "a", -- Enable mouse support
|
||||
number = true, -- Show numberline
|
||||
preserveindent = true, -- Preserve indent structure as much as possible
|
||||
pumheight = 10, -- Height of the pop up menu
|
||||
relativenumber = true, -- Show relative numberline
|
||||
scrolloff = 8, -- Number of lines to keep above and below the cursor
|
||||
shiftwidth = 2, -- Number of space inserted for indentation
|
||||
showmode = false, -- Disable showing modes in command line
|
||||
sidescrolloff = 8, -- Number of columns to keep at the sides of the cursor
|
||||
signcolumn = "yes", -- Always show the sign column
|
||||
smartcase = true, -- Case sensitivie searching
|
||||
splitbelow = true, -- Splitting a new window below the current one
|
||||
splitright = true, -- Splitting a new window at the right of the current one
|
||||
swapfile = false, -- Disable use of swapfile for the buffer
|
||||
tabstop = 2, -- Number of space in a tab
|
||||
termguicolors = true, -- Enable 24-bit RGB color in the TUI
|
||||
timeoutlen = 300, -- Length of time to wait for a mapped sequence
|
||||
undofile = true, -- Enable persistent undo
|
||||
updatetime = 300, -- Length of time to wait before triggering the plugin
|
||||
wrap = false, -- Disable wrapping of lines longer than the width of window
|
||||
writebackup = false, -- Disable making a backup before overwriting a file
|
||||
},
|
||||
g = {
|
||||
do_filetype_lua = 1, -- use filetype.lua
|
||||
did_load_filetypes = 0, -- don't use filetype.vim
|
||||
highlighturl_enabled = true, -- highlight URLs by default
|
||||
mapleader = " ", -- set leader key
|
||||
zipPlugin = false, -- disable zip
|
||||
load_black = false, -- disable black
|
||||
loaded_2html_plugin = true, -- disable 2html
|
||||
loaded_getscript = true, -- disable getscript
|
||||
loaded_getscriptPlugin = true, -- disable getscript
|
||||
loaded_gzip = true, -- disable gzip
|
||||
loaded_logipat = true, -- disable logipat
|
||||
loaded_matchit = true, -- disable matchit
|
||||
loaded_netrwFileHandlers = true, -- disable netrw
|
||||
loaded_netrwPlugin = true, -- disable netrw
|
||||
loaded_netrwSettngs = true, -- disable netrw
|
||||
loaded_remote_plugins = true, -- disable remote plugins
|
||||
loaded_tar = true, -- disable tar
|
||||
loaded_tarPlugin = true, -- disable tar
|
||||
loaded_zip = true, -- disable zip
|
||||
loaded_zipPlugin = true, -- disable zip
|
||||
loaded_vimball = true, -- disable vimball
|
||||
loaded_vimballPlugin = true, -- disable vimball
|
||||
},
|
||||
}))
|
||||
|
||||
local colorscheme = astronvim.user_plugin_opts("colorscheme", nil, false)
|
||||
vim.api.nvim_command(
|
||||
"colorscheme "
|
||||
.. (vim.tbl_contains(vim.fn.getcompletion("", "color"), colorscheme) and colorscheme or "default_theme")
|
||||
)
|
||||
@@ -0,0 +1,354 @@
|
||||
local astro_plugins = {
|
||||
-- Plugin manager
|
||||
["wbthomason/packer.nvim"] = {},
|
||||
|
||||
-- Optimiser
|
||||
["lewis6991/impatient.nvim"] = {},
|
||||
|
||||
-- Lua functions
|
||||
["nvim-lua/plenary.nvim"] = { module = "plenary" },
|
||||
|
||||
-- Popup API
|
||||
["nvim-lua/popup.nvim"] = {},
|
||||
|
||||
-- Indent detection
|
||||
["Darazaki/indent-o-matic"] = {
|
||||
event = "BufReadPost",
|
||||
config = function()
|
||||
require "configs.indent-o-matic"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Notification Enhancer
|
||||
["rcarriga/nvim-notify"] = {
|
||||
event = "VimEnter",
|
||||
config = function()
|
||||
require "configs.notify"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Neovim UI Enhancer
|
||||
["MunifTanjim/nui.nvim"] = { module = "nui" },
|
||||
|
||||
-- Cursorhold fix
|
||||
["antoinemadec/FixCursorHold.nvim"] = {
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
config = function()
|
||||
vim.g.cursorhold_updatetime = 100
|
||||
end,
|
||||
},
|
||||
|
||||
-- Smarter Splits
|
||||
["mrjones2014/smart-splits.nvim"] = {
|
||||
module = "smart-splits",
|
||||
config = function()
|
||||
require "configs.smart-splits"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Icons
|
||||
["kyazdani42/nvim-web-devicons"] = {
|
||||
event = "VimEnter",
|
||||
config = function()
|
||||
require "configs.icons"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Bufferline
|
||||
["akinsho/bufferline.nvim"] = {
|
||||
after = "nvim-web-devicons",
|
||||
config = function()
|
||||
require "configs.bufferline"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Better buffer closing
|
||||
["famiu/bufdelete.nvim"] = { cmd = { "Bdelete", "Bwipeout" } },
|
||||
|
||||
-- File explorer
|
||||
["nvim-neo-tree/neo-tree.nvim"] = {
|
||||
branch = "v2.x",
|
||||
module = "neo-tree",
|
||||
cmd = "Neotree",
|
||||
requires = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim" },
|
||||
setup = function()
|
||||
vim.g.neo_tree_remove_legacy_commands = true
|
||||
end,
|
||||
config = function()
|
||||
require "configs.neo-tree"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Statusline
|
||||
["feline-nvim/feline.nvim"] = {
|
||||
after = "nvim-web-devicons",
|
||||
config = function()
|
||||
require "configs.feline"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Parenthesis highlighting
|
||||
["p00f/nvim-ts-rainbow"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Autoclose tags
|
||||
["windwp/nvim-ts-autotag"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Context based commenting
|
||||
["JoosepAlviste/nvim-ts-context-commentstring"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Syntax highlighting
|
||||
["nvim-treesitter/nvim-treesitter"] = {
|
||||
run = ":TSUpdate",
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
cmd = {
|
||||
"TSInstall",
|
||||
"TSInstallInfo",
|
||||
"TSInstallSync",
|
||||
"TSUninstall",
|
||||
"TSUpdate",
|
||||
"TSUpdateSync",
|
||||
"TSDisableAll",
|
||||
"TSEnableAll",
|
||||
},
|
||||
config = function()
|
||||
require "configs.treesitter"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Snippet collection
|
||||
["rafamadriz/friendly-snippets"] = { opt = true },
|
||||
|
||||
-- Snippet engine
|
||||
["L3MON4D3/LuaSnip"] = {
|
||||
module = "luasnip",
|
||||
wants = "friendly-snippets",
|
||||
config = function()
|
||||
require "configs.luasnip"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Completion engine
|
||||
["hrsh7th/nvim-cmp"] = {
|
||||
event = "InsertEnter",
|
||||
config = function()
|
||||
require "configs.cmp"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Snippet completion source
|
||||
["saadparwaiz1/cmp_luasnip"] = {
|
||||
after = "nvim-cmp",
|
||||
config = function()
|
||||
astronvim.add_user_cmp_source "luasnip"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Buffer completion source
|
||||
["hrsh7th/cmp-buffer"] = {
|
||||
after = "nvim-cmp",
|
||||
config = function()
|
||||
astronvim.add_user_cmp_source "buffer"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Path completion source
|
||||
["hrsh7th/cmp-path"] = {
|
||||
after = "nvim-cmp",
|
||||
config = function()
|
||||
astronvim.add_user_cmp_source "path"
|
||||
end,
|
||||
},
|
||||
|
||||
-- LSP completion source
|
||||
["hrsh7th/cmp-nvim-lsp"] = {
|
||||
after = "nvim-cmp",
|
||||
config = function()
|
||||
astronvim.add_user_cmp_source "nvim_lsp"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Built-in LSP
|
||||
["neovim/nvim-lspconfig"] = { event = "VimEnter" },
|
||||
|
||||
-- LSP manager
|
||||
["williamboman/nvim-lsp-installer"] = {
|
||||
after = "nvim-lspconfig",
|
||||
config = function()
|
||||
require "configs.nvim-lsp-installer"
|
||||
require "configs.lsp"
|
||||
end,
|
||||
},
|
||||
|
||||
-- LSP symbols
|
||||
["stevearc/aerial.nvim"] = {
|
||||
module = "aerial",
|
||||
cmd = { "AerialToggle", "AerialOpen", "AerialInfo" },
|
||||
config = function()
|
||||
require "configs.aerial"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Formatting and linting
|
||||
["jose-elias-alvarez/null-ls.nvim"] = {
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
config = function()
|
||||
require "configs.null-ls"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Fuzzy finder
|
||||
["nvim-telescope/telescope.nvim"] = {
|
||||
cmd = "Telescope",
|
||||
module = "telescope",
|
||||
config = function()
|
||||
require "configs.telescope"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Fuzzy finder syntax support
|
||||
[("nvim-telescope/telescope-%s-native.nvim"):format(vim.fn.has "win32" == 1 and "fzy" or "fzf")] = {
|
||||
after = "telescope.nvim",
|
||||
run = vim.fn.has "win32" ~= 1 and "make" or nil,
|
||||
config = function()
|
||||
require("telescope").load_extension(vim.fn.has "win32" == 1 and "fzy_native" or "fzf")
|
||||
end,
|
||||
},
|
||||
|
||||
-- Git integration
|
||||
["lewis6991/gitsigns.nvim"] = {
|
||||
event = "BufEnter",
|
||||
config = function()
|
||||
require "configs.gitsigns"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Start screen
|
||||
["goolord/alpha-nvim"] = {
|
||||
cmd = "Alpha",
|
||||
module = "alpha",
|
||||
config = function()
|
||||
require "configs.alpha"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Color highlighting
|
||||
["norcalli/nvim-colorizer.lua"] = {
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
config = function()
|
||||
require "configs.colorizer"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Autopairs
|
||||
["windwp/nvim-autopairs"] = {
|
||||
event = "InsertEnter",
|
||||
config = function()
|
||||
require "configs.autopairs"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Terminal
|
||||
["akinsho/toggleterm.nvim"] = {
|
||||
cmd = "ToggleTerm",
|
||||
module = { "toggleterm", "toggleterm.terminal" },
|
||||
config = function()
|
||||
require "configs.toggleterm"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Commenting
|
||||
["numToStr/Comment.nvim"] = {
|
||||
module = { "Comment", "Comment.api" },
|
||||
keys = { "gc", "gb", "g<", "g>" },
|
||||
config = function()
|
||||
require "configs.Comment"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Indentation
|
||||
["lukas-reineke/indent-blankline.nvim"] = {
|
||||
event = "BufRead",
|
||||
config = function()
|
||||
require "configs.indent-line"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Keymaps popup
|
||||
["folke/which-key.nvim"] = {
|
||||
module = "which-key",
|
||||
config = function()
|
||||
require "configs.which-key"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Smooth scrolling
|
||||
["declancm/cinnamon.nvim"] = {
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
config = function()
|
||||
require "configs.cinnamon"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Smooth escaping
|
||||
["max397574/better-escape.nvim"] = {
|
||||
event = "InsertCharPre",
|
||||
config = function()
|
||||
require "configs.better_escape"
|
||||
end,
|
||||
},
|
||||
|
||||
-- Get extra JSON schemas
|
||||
["b0o/SchemaStore.nvim"] = { module = "schemastore" },
|
||||
|
||||
-- Session manager
|
||||
["Shatur/neovim-session-manager"] = {
|
||||
module = "session_manager",
|
||||
cmd = "SessionManager",
|
||||
event = "BufWritePost",
|
||||
config = function()
|
||||
require "configs.session_manager"
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
if astronvim.updater.snapshot then
|
||||
for plugin, options in pairs(astro_plugins) do
|
||||
local pin = astronvim.updater.snapshot[plugin:match "/([^/]*)$"]
|
||||
options.commit = pin and pin.commit or options.commit
|
||||
end
|
||||
end
|
||||
|
||||
local user_plugin_opts = astronvim.user_plugin_opts
|
||||
local packer = astronvim.initialize_packer()
|
||||
packer.startup {
|
||||
function(use)
|
||||
for key, plugin in pairs(user_plugin_opts("plugins.init", astro_plugins)) do
|
||||
if type(key) == "string" and not plugin[1] then
|
||||
plugin[1] = key
|
||||
end
|
||||
use(plugin)
|
||||
end
|
||||
end,
|
||||
config = user_plugin_opts("plugins.packer", {
|
||||
compile_path = astronvim.default_compile_path,
|
||||
display = {
|
||||
open_fn = function()
|
||||
return require("packer.util").float { border = "rounded" }
|
||||
end,
|
||||
},
|
||||
profile = {
|
||||
enable = true,
|
||||
threshold = 0.0001,
|
||||
},
|
||||
git = {
|
||||
clone_timeout = 300,
|
||||
subcommands = {
|
||||
update = "pull --rebase",
|
||||
},
|
||||
},
|
||||
auto_clean = true,
|
||||
compile_on_sync = true,
|
||||
}),
|
||||
}
|
||||
|
||||
astronvim.compiled()
|
||||
@@ -0,0 +1,122 @@
|
||||
local M = { hl = {}, provider = {}, conditional = {} }
|
||||
local C = require "default_theme.colors"
|
||||
|
||||
local function hl_by_name(name)
|
||||
return string.format("#%06x", vim.api.nvim_get_hl_by_name(name.group, true)[name.prop])
|
||||
end
|
||||
|
||||
local function hl_prop(group, prop)
|
||||
local status_ok, color = pcall(hl_by_name, { group = group, prop = prop })
|
||||
return status_ok and color or nil
|
||||
end
|
||||
|
||||
M.modes = {
|
||||
["n"] = { "NORMAL", "Normal", C.blue },
|
||||
["no"] = { "N-PENDING", "Normal", C.blue },
|
||||
["i"] = { "INSERT", "Insert", C.green },
|
||||
["ic"] = { "INSERT", "Insert", C.green },
|
||||
["t"] = { "TERMINAL", "Insert", C.green },
|
||||
["v"] = { "VISUAL", "Visual", C.purple },
|
||||
["V"] = { "V-LINE", "Visual", C.purple },
|
||||
[""] = { "V-BLOCK", "Visual", C.purple },
|
||||
["R"] = { "REPLACE", "Replace", C.red_1 },
|
||||
["Rv"] = { "V-REPLACE", "Replace", C.red_1 },
|
||||
["s"] = { "SELECT", "Visual", C.orange_1 },
|
||||
["S"] = { "S-LINE", "Visual", C.orange_1 },
|
||||
[""] = { "S-BLOCK", "Visual", C.orange_1 },
|
||||
["c"] = { "COMMAND", "Command", C.yellow_1 },
|
||||
["cv"] = { "COMMAND", "Command", C.yellow_1 },
|
||||
["ce"] = { "COMMAND", "Command", C.yellow_1 },
|
||||
["r"] = { "PROMPT", "Inactive", C.grey_7 },
|
||||
["rm"] = { "MORE", "Inactive", C.grey_7 },
|
||||
["r?"] = { "CONFIRM", "Inactive", C.grey_7 },
|
||||
["!"] = { "SHELL", "Inactive", C.grey_7 },
|
||||
}
|
||||
|
||||
function M.hl.group(hlgroup, base)
|
||||
return vim.tbl_deep_extend(
|
||||
"force",
|
||||
base or {},
|
||||
{ fg = hl_prop(hlgroup, "foreground"), bg = hl_prop(hlgroup, "background") }
|
||||
)
|
||||
end
|
||||
|
||||
function M.hl.fg(hlgroup, base)
|
||||
return vim.tbl_deep_extend("force", base or {}, { fg = hl_prop(hlgroup, "foreground") })
|
||||
end
|
||||
|
||||
function M.hl.mode(base)
|
||||
local lualine_avail, lualine = pcall(require, "lualine.themes." .. (vim.g.colors_name or "default_theme"))
|
||||
return function()
|
||||
local lualine_opts = lualine_avail and lualine[M.modes[vim.fn.mode()][2]:lower()]
|
||||
return M.hl.group(
|
||||
"Feline" .. M.modes[vim.fn.mode()][2],
|
||||
vim.tbl_deep_extend(
|
||||
"force",
|
||||
lualine_opts and type(lualine_opts.a) == "table" and lualine_opts.a
|
||||
or { fg = C.bg_1, bg = M.modes[vim.fn.mode()][3] },
|
||||
base or {}
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function M.provider.lsp_progress()
|
||||
local Lsp = vim.lsp.util.get_progress_messages()[1]
|
||||
return Lsp
|
||||
and string.format(
|
||||
" %%<%s %s %s (%s%%%%) ",
|
||||
((Lsp.percentage or 0) >= 70 and { "", "", "" } or { "", "", "" })[math.floor(
|
||||
vim.loop.hrtime() / 12e7
|
||||
) % 3 + 1],
|
||||
Lsp.title or "",
|
||||
Lsp.message or "",
|
||||
Lsp.percentage or 0
|
||||
)
|
||||
or ""
|
||||
end
|
||||
|
||||
function M.provider.lsp_client_names(expand_null_ls)
|
||||
return function()
|
||||
local buf_client_names = {}
|
||||
for _, client in pairs(vim.lsp.buf_get_clients(0)) do
|
||||
if client.name == "null-ls" and expand_null_ls then
|
||||
vim.list_extend(buf_client_names, astronvim.null_ls_sources(vim.bo.filetype, "FORMATTING"))
|
||||
vim.list_extend(buf_client_names, astronvim.null_ls_sources(vim.bo.filetype, "DIAGNOSTICS"))
|
||||
else
|
||||
table.insert(buf_client_names, client.name)
|
||||
end
|
||||
end
|
||||
return table.concat(buf_client_names, ", ")
|
||||
end
|
||||
end
|
||||
|
||||
function M.provider.treesitter_status()
|
||||
local ts = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()]
|
||||
return (ts and next(ts)) and " 綠TS" or ""
|
||||
end
|
||||
|
||||
function M.provider.spacer(n)
|
||||
return string.rep(" ", n or 1)
|
||||
end
|
||||
|
||||
function M.conditional.git_available()
|
||||
return vim.b.gitsigns_head ~= nil
|
||||
end
|
||||
|
||||
function M.conditional.git_changed()
|
||||
local git_status = vim.b.gitsigns_status_dict
|
||||
return git_status and (git_status.added or 0) + (git_status.removed or 0) + (git_status.changed or 0) > 0
|
||||
end
|
||||
|
||||
function M.conditional.has_filetype()
|
||||
return vim.fn.empty(vim.fn.expand "%:t") ~= 1 and vim.bo.filetype and vim.bo.filetype ~= ""
|
||||
end
|
||||
|
||||
function M.conditional.bar_width(n)
|
||||
return function()
|
||||
return (vim.opt.laststatus:get() == 3 and vim.opt.columns:get() or vim.fn.winwidth(0)) > (n or 80)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,143 @@
|
||||
local ui = {}
|
||||
|
||||
function ui.nui_input()
|
||||
-- Set up NUI for UI Input
|
||||
-- From: https://github.com/MunifTanjim/nui.nvim/wiki/vim.ui#vimuiinput
|
||||
local input_ui
|
||||
vim.ui.input = function(opts, on_confirm)
|
||||
local Input = require "nui.input"
|
||||
local event = require("nui.utils.autocmd").event
|
||||
if input_ui then
|
||||
-- ensure single ui.input operation
|
||||
vim.api.nvim_err_writeln "busy: another input is pending!"
|
||||
return
|
||||
end
|
||||
|
||||
local function on_done(value)
|
||||
if input_ui then
|
||||
-- if it's still mounted, unmount it
|
||||
input_ui:unmount()
|
||||
end
|
||||
-- pass the input value
|
||||
on_confirm(value)
|
||||
-- indicate the operation is done
|
||||
input_ui = nil
|
||||
end
|
||||
|
||||
local border_top_text = opts.prompt or "[Input]"
|
||||
local default_value = opts.default
|
||||
|
||||
input_ui = Input({
|
||||
relative = "cursor",
|
||||
position = {
|
||||
row = 1,
|
||||
col = 0,
|
||||
},
|
||||
size = {
|
||||
-- minimum width 20
|
||||
width = math.max(20, type(default_value) == "string" and #default_value or 0),
|
||||
},
|
||||
border = {
|
||||
style = "rounded",
|
||||
highlight = "Normal",
|
||||
text = {
|
||||
top = border_top_text,
|
||||
top_align = "left",
|
||||
},
|
||||
},
|
||||
win_options = {
|
||||
winhighlight = "Normal:Normal",
|
||||
},
|
||||
}, {
|
||||
default_value = default_value,
|
||||
on_close = function()
|
||||
on_done(nil)
|
||||
end,
|
||||
on_submit = function(value)
|
||||
on_done(value)
|
||||
end,
|
||||
})
|
||||
|
||||
input_ui:mount()
|
||||
|
||||
-- cancel operation if cursor leaves input
|
||||
input_ui:on(event.BufLeave, function()
|
||||
on_done(nil)
|
||||
end, { once = true })
|
||||
|
||||
-- cancel operation if <Esc> is pressed
|
||||
input_ui:map("n", "<Esc>", function()
|
||||
on_done(nil)
|
||||
end, { noremap = true, nowait = true })
|
||||
end
|
||||
end
|
||||
|
||||
function ui.telescope_select()
|
||||
-- Telescope UI selection
|
||||
-- From: https://github.com/stevearc/dressing.nvim/blob/master/lua/dressing/select/telescope.lua
|
||||
vim.ui.select = vim.schedule_wrap(function(items, opts, on_choice)
|
||||
local themes = require "telescope.themes"
|
||||
local actions = require "telescope.actions"
|
||||
local state = require "telescope.actions.state"
|
||||
local pickers = require "telescope.pickers"
|
||||
local finders = require "telescope.finders"
|
||||
local conf = require("telescope.config").values
|
||||
|
||||
if opts.format_item then
|
||||
local format_item = opts.format_item
|
||||
opts.format_item = function(item)
|
||||
return tostring(format_item(item))
|
||||
end
|
||||
else
|
||||
opts.format_item = tostring
|
||||
end
|
||||
|
||||
local entry_maker = function(item)
|
||||
local formatted = opts.format_item(item)
|
||||
return {
|
||||
display = formatted,
|
||||
ordinal = formatted,
|
||||
value = item,
|
||||
}
|
||||
end
|
||||
|
||||
local picker_opts = themes.get_dropdown()
|
||||
|
||||
pickers.new(picker_opts, {
|
||||
prompt_title = opts.prompt,
|
||||
previewer = false,
|
||||
finder = finders.new_table {
|
||||
results = items,
|
||||
entry_maker = entry_maker,
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local selection = state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
if not selection then
|
||||
-- User did not select anything.
|
||||
on_choice(nil, nil)
|
||||
return
|
||||
end
|
||||
local idx = nil
|
||||
for i, item in ipairs(items) do
|
||||
if item == selection.value then
|
||||
idx = i
|
||||
break
|
||||
end
|
||||
end
|
||||
on_choice(selection.value, idx)
|
||||
end)
|
||||
|
||||
actions.close:enhance { post = function() end }
|
||||
|
||||
return true
|
||||
end,
|
||||
}):find()
|
||||
end)
|
||||
end
|
||||
|
||||
for ui_addition, enabled in pairs(astronvim.user_plugin_opts("ui", { nui_input = true, telescope_select = true })) do
|
||||
astronvim.conditional_func(ui[ui_addition], enabled)
|
||||
end
|
||||
@@ -0,0 +1,101 @@
|
||||
local git = { url = "https://github.com/" }
|
||||
|
||||
function git.cmd(args, ...)
|
||||
return astronvim.cmd("git -C " .. astronvim.install.home .. " " .. args, ...)
|
||||
end
|
||||
|
||||
function git.is_repo()
|
||||
return git.cmd("rev-parse --is-inside-work-tree", false)
|
||||
end
|
||||
|
||||
function git.fetch(remote, ...)
|
||||
return git.cmd("fetch " .. remote, ...)
|
||||
end
|
||||
|
||||
function git.pull(...)
|
||||
return git.cmd("pull --rebase", ...)
|
||||
end
|
||||
|
||||
function git.checkout(dest, ...)
|
||||
return git.cmd("checkout " .. dest, ...)
|
||||
end
|
||||
|
||||
function git.hard_reset(dest, ...)
|
||||
return git.cmd("reset --hard " .. dest, ...)
|
||||
end
|
||||
|
||||
function git.branch_contains(remote, branch, commit, ...)
|
||||
return git.cmd("merge-base --is-ancestor " .. commit .. " " .. remote .. "/" .. branch, ...) ~= nil
|
||||
end
|
||||
|
||||
function git.remote_add(remote, url, ...)
|
||||
return git.cmd("remote add " .. remote .. " " .. url, ...)
|
||||
end
|
||||
|
||||
function git.remote_update(remote, url, ...)
|
||||
return git.cmd("remote set-url " .. remote .. " " .. url, ...)
|
||||
end
|
||||
|
||||
function git.remote_url(remote, ...)
|
||||
return astronvim.trim_or_nil(git.cmd("remote get-url " .. remote, ...))
|
||||
end
|
||||
|
||||
function git.current_version(...)
|
||||
return astronvim.trim_or_nil(git.cmd("describe --tags", ...))
|
||||
end
|
||||
|
||||
function git.current_branch(...)
|
||||
return astronvim.trim_or_nil(git.cmd("rev-parse --abbrev-ref HEAD", ...))
|
||||
end
|
||||
|
||||
function git.local_head(...)
|
||||
return astronvim.trim_or_nil(git.cmd("rev-parse HEAD", ...))
|
||||
end
|
||||
|
||||
function git.remote_head(remote, branch, ...)
|
||||
return astronvim.trim_or_nil(git.cmd("rev-list -n 1 " .. remote .. "/" .. branch, ...))
|
||||
end
|
||||
|
||||
function git.tag_commit(tag, ...)
|
||||
return astronvim.trim_or_nil(git.cmd("rev-list -n 1 " .. tag, ...))
|
||||
end
|
||||
|
||||
function git.get_commit_range(start_hash, end_hash, ...)
|
||||
local log = git.cmd("log --no-merges --pretty='format:[%h] %s' " .. start_hash .. ".." .. end_hash, ...)
|
||||
return log and vim.fn.split(log, "\n") or {}
|
||||
end
|
||||
|
||||
function git.get_versions(search, ...)
|
||||
local tags = git.cmd("tag -l --sort=version:refname '" .. (search == "latest" and "v*" or search) .. "'", ...)
|
||||
return tags and vim.fn.split(tags, "\n") or {}
|
||||
end
|
||||
|
||||
function git.latest_version(versions, ...)
|
||||
versions = versions and versions or git.get_versions(...)
|
||||
return versions[#versions]
|
||||
end
|
||||
|
||||
function git.parse_remote_url(str)
|
||||
return vim.fn.match(str, astronvim.url_matcher) == -1
|
||||
and git.url .. str .. (vim.fn.match(str, "/") == -1 and "/AstroNvim.git" or ".git")
|
||||
or str
|
||||
end
|
||||
|
||||
function git.breaking_changes(commits)
|
||||
return vim.tbl_filter(function(v)
|
||||
return vim.fn.match(v, "\\[.*\\]\\s\\+\\w\\+\\((\\w\\+)\\)\\?!:") ~= -1
|
||||
end, commits)
|
||||
end
|
||||
|
||||
function git.pretty_changelog(commits)
|
||||
local changelog = {}
|
||||
for _, commit in ipairs(commits) do
|
||||
local hash, type, msg = commit:match "(%[.*%])(.*:)(.*)"
|
||||
if hash and type and msg then
|
||||
vim.list_extend(changelog, { { hash, "DiffText" }, { type, "Typedef" }, { msg }, { "\n" } })
|
||||
end
|
||||
end
|
||||
return changelog
|
||||
end
|
||||
|
||||
return git
|
||||
@@ -0,0 +1,299 @@
|
||||
_G.astronvim = {}
|
||||
local stdpath = vim.fn.stdpath
|
||||
local tbl_insert = table.insert
|
||||
local map = vim.keymap.set
|
||||
|
||||
astronvim.install = astronvim_installation or { home = stdpath "config" }
|
||||
|
||||
local astronvim_config = stdpath("config"):gsub("nvim$", "astronvim")
|
||||
vim.opt.rtp:append(astronvim_config)
|
||||
local supported_configs = { astronvim.install.home, astronvim_config }
|
||||
|
||||
local function load_module_file(module)
|
||||
local found_module = nil
|
||||
for _, config_path in ipairs(supported_configs) do
|
||||
local module_path = config_path .. "/lua/" .. module:gsub("%.", "/") .. ".lua"
|
||||
if vim.fn.filereadable(module_path) == 1 then
|
||||
found_module = module_path
|
||||
end
|
||||
end
|
||||
if found_module then
|
||||
local status_ok, loaded_module = pcall(require, module)
|
||||
if status_ok then
|
||||
found_module = loaded_module
|
||||
else
|
||||
astronvim.notify("Error loading " .. found_module, "error")
|
||||
end
|
||||
end
|
||||
return found_module
|
||||
end
|
||||
|
||||
astronvim.user_settings = load_module_file "user.init"
|
||||
astronvim.default_compile_path = stdpath "data" .. "/packer_compiled.lua"
|
||||
astronvim.user_terminals = {}
|
||||
astronvim.url_matcher =
|
||||
"\\v\\c%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)%([&:#*@~%_\\-=?!+;/0-9a-z]+%(%([.;/?]|[.][.]+)[&:#*@~%_\\-=?!+/0-9a-z]+|:\\d+|,%(%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)@![0-9a-z]+))*|\\([&:#*@~%_\\-=?!+;/.0-9a-z]*\\)|\\[[&:#*@~%_\\-=?!+;/.0-9a-z]*\\]|\\{%([&:#*@~%_\\-=?!+;/.0-9a-z]*|\\{[&:#*@~%_\\-=?!+;/.0-9a-z]*})\\})+"
|
||||
|
||||
local function func_or_extend(overrides, default, extend)
|
||||
if extend then
|
||||
if type(overrides) == "table" then
|
||||
default = vim.tbl_deep_extend("force", default, overrides)
|
||||
elseif type(overrides) == "function" then
|
||||
default = overrides(default)
|
||||
end
|
||||
elseif overrides ~= nil then
|
||||
default = overrides
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
function astronvim.conditional_func(func, condition, ...)
|
||||
if (condition == nil and true or condition) and type(func) == "function" then
|
||||
return func(...)
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.trim_or_nil(str)
|
||||
return type(str) == "string" and vim.trim(str) or nil
|
||||
end
|
||||
|
||||
function astronvim.notify(msg, type, opts)
|
||||
vim.notify(msg, type, vim.tbl_deep_extend("force", { title = "AstroNvim" }, opts or {}))
|
||||
end
|
||||
|
||||
function astronvim.echo(messages)
|
||||
messages = messages or { { "\n" } }
|
||||
if type(messages) == "table" then
|
||||
vim.api.nvim_echo(messages, false, {})
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.confirm_prompt(messages)
|
||||
if messages then
|
||||
astronvim.echo(messages)
|
||||
end
|
||||
local confirmed = string.lower(vim.fn.input "(y/n) ") == "y"
|
||||
astronvim.echo()
|
||||
astronvim.echo()
|
||||
return confirmed
|
||||
end
|
||||
|
||||
local function user_setting_table(module)
|
||||
local settings = astronvim.user_settings or {}
|
||||
for tbl in string.gmatch(module, "([^%.]+)") do
|
||||
settings = settings[tbl]
|
||||
if settings == nil then
|
||||
break
|
||||
end
|
||||
end
|
||||
return settings
|
||||
end
|
||||
|
||||
function astronvim.initialize_packer()
|
||||
local packer_avail, packer = pcall(require, "packer")
|
||||
if not packer_avail then
|
||||
local packer_path = stdpath "data" .. "/site/pack/packer/start/packer.nvim"
|
||||
vim.fn.delete(packer_path, "rf")
|
||||
vim.fn.system {
|
||||
"git",
|
||||
"clone",
|
||||
"--depth",
|
||||
"1",
|
||||
"https://github.com/wbthomason/packer.nvim",
|
||||
packer_path,
|
||||
}
|
||||
astronvim.echo { { "Initializing Packer...\n\n" } }
|
||||
vim.cmd "packadd packer.nvim"
|
||||
packer_avail, packer = pcall(require, "packer")
|
||||
if not packer_avail then
|
||||
vim.api.nvim_err_writeln("Failed to load packer at:" .. packer_path .. "\n\n" .. packer)
|
||||
end
|
||||
end
|
||||
return packer
|
||||
end
|
||||
|
||||
function astronvim.vim_opts(options)
|
||||
for scope, table in pairs(options) do
|
||||
for setting, value in pairs(table) do
|
||||
vim[scope][setting] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.user_plugin_opts(module, default, extend, prefix)
|
||||
if extend == nil then
|
||||
extend = true
|
||||
end
|
||||
default = default or {}
|
||||
local user_settings = load_module_file((prefix or "user") .. "." .. module)
|
||||
if user_settings == nil and prefix == nil then
|
||||
user_settings = user_setting_table(module)
|
||||
end
|
||||
if user_settings ~= nil then
|
||||
default = func_or_extend(user_settings, default, extend)
|
||||
end
|
||||
return default
|
||||
end
|
||||
|
||||
function astronvim.compiled()
|
||||
local run_me, _ = loadfile(
|
||||
astronvim.user_plugin_opts("plugins.packer", { compile_path = astronvim.default_compile_path }).compile_path
|
||||
)
|
||||
if run_me then
|
||||
run_me()
|
||||
else
|
||||
astronvim.echo { { "Please run " }, { ":PackerSync", "Title" } }
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.url_opener()
|
||||
if vim.fn.has "mac" == 1 then
|
||||
vim.fn.jobstart({ "open", vim.fn.expand "<cfile>" }, { detach = true })
|
||||
elseif vim.fn.has "unix" == 1 then
|
||||
vim.fn.jobstart({ "xdg-open", vim.fn.expand "<cfile>" }, { detach = true })
|
||||
else
|
||||
astronvim.notify("gx is not supported on this OS!", "error")
|
||||
end
|
||||
end
|
||||
|
||||
-- term_details can be either a string for just a command or
|
||||
-- a complete table to provide full access to configuration when calling Terminal:new()
|
||||
function astronvim.toggle_term_cmd(term_details)
|
||||
if type(term_details) == "string" then
|
||||
term_details = { cmd = term_details, hidden = true }
|
||||
end
|
||||
local term_key = term_details.cmd
|
||||
if vim.v.count > 0 and term_details.count == nil then
|
||||
term_details.count = vim.v.count
|
||||
term_key = term_key .. vim.v.count
|
||||
end
|
||||
if astronvim.user_terminals[term_key] == nil then
|
||||
astronvim.user_terminals[term_key] = require("toggleterm.terminal").Terminal:new(term_details)
|
||||
end
|
||||
astronvim.user_terminals[term_key]:toggle()
|
||||
end
|
||||
|
||||
function astronvim.add_cmp_source(source)
|
||||
local cmp_avail, cmp = pcall(require, "cmp")
|
||||
if cmp_avail then
|
||||
local config = cmp.get_config()
|
||||
tbl_insert(config.sources, source)
|
||||
cmp.setup(config)
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.get_user_cmp_source(source)
|
||||
source = type(source) == "string" and { name = source } or source
|
||||
local priority = astronvim.user_plugin_opts("cmp.source_priority", {
|
||||
nvim_lsp = 1000,
|
||||
luasnip = 750,
|
||||
buffer = 500,
|
||||
path = 250,
|
||||
})[source.name]
|
||||
if priority then
|
||||
source.priority = priority
|
||||
end
|
||||
return source
|
||||
end
|
||||
|
||||
function astronvim.add_user_cmp_source(source)
|
||||
astronvim.add_cmp_source(astronvim.get_user_cmp_source(source))
|
||||
end
|
||||
|
||||
function astronvim.null_ls_providers(filetype)
|
||||
local registered = {}
|
||||
local sources_avail, sources = pcall(require, "null-ls.sources")
|
||||
if sources_avail then
|
||||
for _, source in ipairs(sources.get_available(filetype)) do
|
||||
for method in pairs(source.methods) do
|
||||
registered[method] = registered[method] or {}
|
||||
tbl_insert(registered[method], source.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
return registered
|
||||
end
|
||||
|
||||
function astronvim.null_ls_sources(filetype, source)
|
||||
local methods_avail, methods = pcall(require, "null-ls.methods")
|
||||
return methods_avail and astronvim.null_ls_providers(filetype)[methods.internal[source]] or {}
|
||||
end
|
||||
|
||||
function astronvim.alpha_button(sc, txt)
|
||||
local sc_ = sc:gsub("%s", ""):gsub("LDR", "<leader>")
|
||||
if vim.g.mapleader then
|
||||
sc = sc:gsub("LDR", vim.g.mapleader == " " and "SPC" or vim.g.mapleader)
|
||||
end
|
||||
return {
|
||||
type = "button",
|
||||
val = txt,
|
||||
on_press = function()
|
||||
local key = vim.api.nvim_replace_termcodes(sc_, true, false, true)
|
||||
vim.api.nvim_feedkeys(key, "normal", false)
|
||||
end,
|
||||
opts = {
|
||||
position = "center",
|
||||
text = txt,
|
||||
shortcut = sc,
|
||||
cursor = 5,
|
||||
width = 36,
|
||||
align_shortcut = "right",
|
||||
hl = "DashboardCenter",
|
||||
hl_shortcut = "DashboardShortcut",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
function astronvim.is_available(plugin)
|
||||
return packer_plugins ~= nil and packer_plugins[plugin] ~= nil
|
||||
end
|
||||
|
||||
function astronvim.set_mappings(map_table, base)
|
||||
for mode, maps in pairs(map_table) do
|
||||
for keymap, options in pairs(maps) do
|
||||
if options then
|
||||
local cmd = options
|
||||
if type(options) == "table" then
|
||||
cmd = options[1]
|
||||
options[1] = nil
|
||||
else
|
||||
options = {}
|
||||
end
|
||||
map(mode, keymap, cmd, vim.tbl_deep_extend("force", options, base or {}))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.delete_url_match()
|
||||
for _, match in ipairs(vim.fn.getmatches()) do
|
||||
if match.group == "HighlightURL" then
|
||||
vim.fn.matchdelete(match.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.set_url_match()
|
||||
astronvim.delete_url_match()
|
||||
if vim.g.highlighturl_enabled then
|
||||
vim.fn.matchadd("HighlightURL", astronvim.url_matcher, 15)
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.toggle_url_match()
|
||||
vim.g.highlighturl_enabled = not vim.g.highlighturl_enabled
|
||||
astronvim.set_url_match()
|
||||
end
|
||||
|
||||
function astronvim.cmd(cmd, show_error)
|
||||
local result = vim.fn.system(cmd)
|
||||
local success = vim.api.nvim_get_vvar "shell_error" == 0
|
||||
if not success and (show_error == nil and true or show_error) then
|
||||
vim.api.nvim_err_writeln("Error running command: " .. cmd .. "\nError message:\n" .. result)
|
||||
end
|
||||
return success and result or nil
|
||||
end
|
||||
|
||||
require "core.utils.updater"
|
||||
|
||||
return astronvim
|
||||
@@ -0,0 +1,160 @@
|
||||
local fn = vim.fn
|
||||
local git = require "core.utils.git"
|
||||
local options = astronvim.user_plugin_opts(
|
||||
"updater",
|
||||
{ remote = "origin", branch = "main", channel = "nightly", show_changelog = true }
|
||||
)
|
||||
|
||||
if astronvim.install.is_stable ~= nil then
|
||||
options.channel = astronvim.install.is_stable and "stable" or "nightly"
|
||||
end
|
||||
|
||||
astronvim.updater = { options = options }
|
||||
if options.pin_plugins == nil and options.channel == "stable" or options.pin_plugins then
|
||||
local loaded, snapshot = pcall(fn.readfile, astronvim.install.home .. "/packer_snapshot")
|
||||
if loaded then
|
||||
loaded, snapshot = pcall(fn.json_decode, snapshot)
|
||||
astronvim.updater.snapshot = type(snapshot) == "table" and snapshot or nil
|
||||
end
|
||||
if not loaded then
|
||||
vim.api.nvim_err_writeln "Error loading packer snapshot"
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.updater.version()
|
||||
local version = astronvim.install.version or git.current_version(false)
|
||||
if version then
|
||||
astronvim.notify("Version: " .. version)
|
||||
end
|
||||
end
|
||||
|
||||
local function attempt_update(target)
|
||||
if options.channel == "stable" or options.commit then
|
||||
return git.checkout(target, false)
|
||||
else
|
||||
return git.pull(false)
|
||||
end
|
||||
end
|
||||
|
||||
local cancelled_message = { { "Update cancelled", "WarningMsg" } }
|
||||
|
||||
function astronvim.updater.update()
|
||||
if not git.is_repo() then
|
||||
astronvim.notify("Updater not available for non-git installations", "error")
|
||||
return
|
||||
end
|
||||
for remote, entry in pairs(options.remotes and options.remotes or {}) do
|
||||
local url = git.parse_remote_url(entry)
|
||||
local current_url = git.remote_url(remote, false)
|
||||
local check_needed = false
|
||||
if not current_url then
|
||||
git.remote_add(remote, url)
|
||||
check_needed = true
|
||||
elseif
|
||||
current_url ~= url
|
||||
and astronvim.confirm_prompt {
|
||||
{ "Remote " },
|
||||
{ remote, "Title" },
|
||||
{ " is currently set to " },
|
||||
{ current_url, "WarningMsg" },
|
||||
{ "\nWould you like us to set it to " },
|
||||
{ url, "String" },
|
||||
{ "?" },
|
||||
}
|
||||
then
|
||||
git.remote_update(remote, url)
|
||||
check_needed = true
|
||||
end
|
||||
if check_needed and git.remote_url(remote, false) ~= url then
|
||||
vim.api.nvim_err_writeln("Error setting up remote " .. remote .. " to " .. url)
|
||||
return
|
||||
end
|
||||
end
|
||||
local is_stable = options.channel == "stable"
|
||||
options.branch = is_stable and "main" or options.branch
|
||||
if not git.fetch(options.remote) then
|
||||
vim.api.nvim_err_writeln("Error fetching remote: " .. options.remote)
|
||||
return
|
||||
end
|
||||
local local_branch = (options.remote == "origin" and "" or (options.remote .. "_")) .. options.branch
|
||||
if git.current_branch() ~= local_branch then
|
||||
astronvim.echo {
|
||||
{ "Switching to branch: " },
|
||||
{ options.remote .. "/" .. options.branch .. "\n\n", "String" },
|
||||
}
|
||||
if not git.checkout(local_branch, false) then
|
||||
git.checkout("-b " .. local_branch .. " " .. options.remote .. "/" .. options.branch, false)
|
||||
end
|
||||
end
|
||||
if git.current_branch() ~= local_branch then
|
||||
vim.api.nvim_err_writeln("Error checking out branch: " .. options.remote .. "/" .. options.branch)
|
||||
return
|
||||
end
|
||||
local source = git.local_head() -- calculate current commit
|
||||
local target -- calculate target commit
|
||||
if is_stable then -- if stable get tag commit
|
||||
options.version = git.latest_version(git.get_versions(options.version or "latest"))
|
||||
target = git.tag_commit(options.version)
|
||||
elseif options.commit then -- if commit specified use it
|
||||
target = git.branch_contains(options.remote, options.branch, options.commit) and options.commit or nil
|
||||
else -- get most recent commit
|
||||
target = git.remote_head(options.remote, options.branch)
|
||||
end
|
||||
if not source or not target then -- continue if current and target commits were found
|
||||
vim.api.nvim_err_writeln "Error checking for updates"
|
||||
return
|
||||
elseif source == target then
|
||||
astronvim.echo { { "No updates available", "String" } }
|
||||
return
|
||||
elseif -- prompt user if they want to accept update
|
||||
not options.skip_prompts
|
||||
and not astronvim.confirm_prompt {
|
||||
{ "Update available to ", "Title" },
|
||||
{ is_stable and options.version or target, "String" },
|
||||
{ "\nContinue?" },
|
||||
}
|
||||
then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
else -- perform update
|
||||
local changelog = git.get_commit_range(source, target)
|
||||
local breaking = git.breaking_changes(changelog)
|
||||
local breaking_prompt = { { "Update contains the following breaking changes:\n", "WarningMsg" } }
|
||||
vim.list_extend(breaking_prompt, git.pretty_changelog(breaking))
|
||||
vim.list_extend(breaking_prompt, { { "\nWould you like to continue?" } })
|
||||
if #breaking > 0 and not options.skip_prompts and not astronvim.confirm_prompt(breaking_prompt) then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
end
|
||||
local updated = attempt_update(target)
|
||||
if
|
||||
not updated
|
||||
and not options.skip_prompts
|
||||
and not astronvim.confirm_prompt {
|
||||
{ "Unable to pull due to local modifications to base files.\n", "ErrorMsg" },
|
||||
{ "Reset local files and continue?" },
|
||||
}
|
||||
then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
elseif not updated then
|
||||
git.hard_reset(source)
|
||||
updated = attempt_update(target)
|
||||
end
|
||||
if not updated then
|
||||
vim.api.nvim_err_writeln "Error ocurred performing update"
|
||||
return
|
||||
end
|
||||
local summary = {
|
||||
{ "AstroNvim updated successfully to ", "Title" },
|
||||
{ git.current_version(), "String" },
|
||||
{ "!\n", "Title" },
|
||||
{ "Please restart and run :PackerSync.\n\n", "WarningMsg" },
|
||||
}
|
||||
if options.show_changelog and #changelog > 0 then
|
||||
vim.list_extend(summary, { { "Changelog:\n", "Title" } })
|
||||
vim.list_extend(summary, git.pretty_changelog(changelog))
|
||||
end
|
||||
astronvim.echo(summary)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user