From dfcfbd004a7d14e08ac7e3a542c39747b6f22c4d Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Tue, 28 Sep 2021 16:43:50 +0700 Subject: [PATCH] neovim: configure packer.nvim + add iswap.nvim --- home/.config/nvim/after/ftplugin/markdown.vim | 1 + home/.config/nvim/after/ftplugin/tex.vim | 1 + home/.config/nvim/init.lua | 2 +- home/.config/nvim/lua/autocmd.lua | 49 ++ home/.config/nvim/lua/colors/nord.lua | 13 +- home/.config/nvim/lua/events.lua | 86 -- home/.config/nvim/lua/mappings.lua | 19 +- home/.config/nvim/lua/modules/completion.lua | 4 +- home/.config/nvim/lua/modules/editor.lua | 29 + home/.config/nvim/lua/modules/lsp.lua | 10 +- home/.config/nvim/lua/modules/pack.lua | 65 ++ home/.config/nvim/lua/modules/tools.lua | 3 + home/.config/nvim/lua/plugins.lua | 787 +++++++++--------- home/.local/bin/doasedit | 104 +++ home/.local/bin/pancomp | 20 - 15 files changed, 670 insertions(+), 523 deletions(-) create mode 100644 home/.config/nvim/lua/autocmd.lua delete mode 100644 home/.config/nvim/lua/events.lua create mode 100644 home/.config/nvim/lua/modules/pack.lua create mode 100755 home/.local/bin/doasedit delete mode 100755 home/.local/bin/pancomp diff --git a/home/.config/nvim/after/ftplugin/markdown.vim b/home/.config/nvim/after/ftplugin/markdown.vim index 265dd39..3b1df70 100644 --- a/home/.config/nvim/after/ftplugin/markdown.vim +++ b/home/.config/nvim/after/ftplugin/markdown.vim @@ -1,2 +1,3 @@ +setlocal spell setlocal wrap " setlocal nonumber norelativenumber diff --git a/home/.config/nvim/after/ftplugin/tex.vim b/home/.config/nvim/after/ftplugin/tex.vim index 265dd39..3b1df70 100644 --- a/home/.config/nvim/after/ftplugin/tex.vim +++ b/home/.config/nvim/after/ftplugin/tex.vim @@ -1,2 +1,3 @@ +setlocal spell setlocal wrap " setlocal nonumber norelativenumber diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index 57ef4ef..1cbcf86 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -2,7 +2,7 @@ local async async = vim.loop.new_async(vim.schedule_wrap(function() require('plugins') require('mappings') - require('events').load_autocmds() + require('autocmd') async:close() end)) diff --git a/home/.config/nvim/lua/autocmd.lua b/home/.config/nvim/lua/autocmd.lua new file mode 100644 index 0000000..643cb4e --- /dev/null +++ b/home/.config/nvim/lua/autocmd.lua @@ -0,0 +1,49 @@ +local definitions = { + -- ':h hex-editing' + binary = { + {'BufReadPre' , '*.bin,*.exe', 'let &bin=1'}, + {'BufReadPost' , '*.bin,*.exe', 'if &bin | %!xxd'}, + {'BufReadPost' , '*.bin,*.exe', 'set ft=xxd | endif'}, + {'BufWritePre' , '*.bin,*.exe', 'if &bin | %!xxd -r'}, + {'BufWritePre' , '*.bin,*.exe', 'endif'}, + {'BufWritePost', '*.bin,*.exe', 'if &bin | %!xxd'}, + {'BufWritePost', '*.bin,*.exe', 'set nomod | endif'} + }, + + -- Auto-hide UI elements in specific buffers + buf = { + {'BufEnter', 'term://*', 'setlocal norelativenumber nonumber'}, + -- {'BufEnter,BufWinEnter,WinEnter,CmdwinEnter', '*', [[if bufname('%') == 'NvimTree' | set laststatus=0 | else | set laststatus=2 | endif]]} + }, + + wins = { + -- Equalize window dimensions when resizing vim window + {'VimResized', '*', 'tabdo wincmd ='}, + -- Force writing shada on leaving nvim + {'VimLeave', '*', [[if has('nvim') | wshada! | else | wviminfo! | endif]]}, + -- Check if file changed when its window is focus, more eager than 'autoread' + {'FocusGained', '* checktime'} + }, + + ft = { + {'BufNewFile,BufRead', '*.md,*.mkd', 'setfiletype markdown'}, + {'BufNewFile,BufRead', '*.toml', 'setfiletype toml'}, + {'BufNewFile,BufRead', '*.rasi', 'setfiletype css'}, + {'BufNewFile,BufRead', 'vifmrc,*.vifm', 'setfiletype vim'}, + {'BufNewFile,BufRead', '*.log,*_log,*.LO,G*_LOG', 'setfiletype log'} + }, + + yank = { + {'TextYankPost', [[* silent! lua vim.highlight.on_yank({higroup='IncSearch', timeout=300})]]} + } +} + +for group_name, definition in pairs(definitions) do + vim.api.nvim_command('augroup ' .. group_name) + vim.api.nvim_command('autocmd!') + for _, def in ipairs(definition) do + local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ') + vim.api.nvim_command(command) + end + vim.api.nvim_command('augroup END') +end diff --git a/home/.config/nvim/lua/colors/nord.lua b/home/.config/nvim/lua/colors/nord.lua index ba644a9..823f320 100644 --- a/home/.config/nvim/lua/colors/nord.lua +++ b/home/.config/nvim/lua/colors/nord.lua @@ -297,22 +297,15 @@ local function highlight_plugins() hi('rainbowcol6', c.blue, '', 'bold', '') hi('rainbowcol7', c.purple, '', 'bold', '') - -- todo-comments - hi('TodoDefault', c.fg, '', 'bold', '') - hi('TodoError', c.red, '', 'bold', '') - hi('TodoWarn', c.yellow, '', 'bold', '') - hi('TodoInfo', c.blue, '', 'bold', '') - hi('TodoHint', c.cyan, '', 'bold', '') - -- hop.nvim hi('HopNextKey', c.red, '', 'bold', '') hi('HopNextKey1', c.cyan, '', 'bold', '') hi('HopNextKey2', c.dark_blue, '', '', '') - hi('HopUnmatched', c.grey3, '', '', '') + vim.api.nvim_command('hi! link HopUnmatched LineNr') -- vim-eft - hi('EftChar' , c.orange, '', 'bold,underline', '') - hi('EftSubChar', c.grey3, '', 'bold,underline', '') + hi('EftChar', c.orange, '', 'bold,underline', '') + vim.api.nvim_command('hi! link EftSubChar LineNr') -- dashboard-nvim / alpha-nvim hi('DashboardHeader' , c.blue , '', 'bold' , '') diff --git a/home/.config/nvim/lua/events.lua b/home/.config/nvim/lua/events.lua deleted file mode 100644 index 45f5514..0000000 --- a/home/.config/nvim/lua/events.lua +++ /dev/null @@ -1,86 +0,0 @@ -local plug_dir = vim.fn.stdpath('config') .. '/lua' -local M = {} - -function M.packer_compile() - local file = vim.fn.expand('%:p') - if file:match(plug_dir) then - vim.api.nvim_command('source | PackerCompile') - end -end - -function M.nvim_create_augroups(definitions) - for group_name, definition in pairs(definitions) do - vim.api.nvim_command('augroup ' .. group_name) - vim.api.nvim_command('autocmd!') - for _, def in ipairs(definition) do - local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ') - vim.api.nvim_command(command) - end - vim.api.nvim_command('augroup END') - end -end - -function M.load_autocmds() - local definitions = { - plugins = { - -- Wrap lines in preview window - -- {"User TelescopePreviewerLoaded", [[setlocal wrap]]}, - - -- Re-compile packer on config changed - {"BufWritePost", "*.lua", "lua require('events').packer_compile()"}, - - -- Register binding for ToggleTerm inside term mode - {"TermEnter", "term://*toggleterm#*", "tnoremap :ToggleTerm"} - }, - - -- Edit binary files in hex with xxd (:%!xxd and :%!xxd -r) - -- or using nvim -b to edit files using xxd-format - binary = { - {"BufReadPre" , "*.bin,*.exe", "let &bin=1"}, - {"BufReadPost" , "*.bin,*.exe", "if &bin | %!xxd"}, - {"BufReadPost" , "*.bin,*.exe", "set ft=xxd | endif"}, - {"BufWritePre" , "*.bin,*.exe", "if &bin | %!xxd -r"}, - {"BufWritePre" , "*.bin,*.exe", "endif"}, - {"BufWritePost", "*.bin,*.exe", "if &bin | %!xxd"}, - {"BufWritePost", "*.bin,*.exe", "set nomod | endif"} - }, - - buf = { - -- Auto-spelling in doc files - {"BufNewFile,BufRead", "*.md,*.mkd", "setlocal spell"}, - {"BufNewFile,BufRead", "*.tex", "setlocal spell"}, - - -- Auto-hide numbers, statusline in specific buffers - -- {"BufEnter", "term://*", "setlocal norelativenumber nonumber"}, - -- {"BufEnter", "term://*", "set laststatus=0"}, - -- {"BufEnter,BufWinEnter,WinEnter,CmdwinEnter", "*", [[if bufname('%') == "NvimTree" | set laststatus=0 | else | set laststatus=2 | endif]]} - }, - - wins = { - -- Equalize window dimensions when resizing vim window - {"VimResized", "*", [[tabdo wincmd =]]}, - - -- Force writing shada on leaving nvim - {"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]}, - - -- Check if file changed when its window is focus, more eager than 'autoread' - {"FocusGained", "* checktime"} - }, - - ft = { - {"BufNewFile,BufRead", "*.md,*.mkd", "setfiletype markdown"}, - {"BufNewFile,BufRead", "*.toml", "setfiletype toml"}, - {"BufNewFile,BufRead", "*.rasi", "setfiletype css"}, - {"BufNewFile,BufRead", "vifmrc,*.vifm", "setfiletype vim"}, - {"BufNewFile,BufRead", "*.log,*_log,*.LO,G*_LOG", "setfiletype log"} - }, - - yank = { - {"TextYankPost", [[* silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=300})]]} - } - } - - M.nvim_create_augroups(definitions) -end - -return M diff --git a/home/.config/nvim/lua/mappings.lua b/home/.config/nvim/lua/mappings.lua index 7040622..0b465ff 100644 --- a/home/.config/nvim/lua/mappings.lua +++ b/home/.config/nvim/lua/mappings.lua @@ -52,10 +52,10 @@ wk.register({ L = {'$', 'End of the line'}, -- Easier moving between windows - [''] = {'h', 'Go to the left window'}, - [''] = {'l', 'Go to the right window'}, - [''] = {'j', 'Go to the down window'}, - [''] = {'k', 'Go to the up window'}, + -- [''] = {'h', 'Go to the left window'}, + -- [''] = {'l', 'Go to the right window'}, + -- [''] = {'j', 'Go to the down window'}, + -- [''] = {'k', 'Go to the up window'}, [''] = {'q', 'Quit a window'}, -- Copy the whole buffer @@ -133,7 +133,11 @@ wk.register({ -- Normal mode (with leader key) -- ----------------------------------- wk.register({ - a = {':EasyAlign', 'Align'}, + a = { + name = 'Action', + a = {':EasyAlign', 'Align elements'}, + s = {':ISwapWith', 'Swap elements'} + }, b = { name = 'Buffer/Tab', @@ -315,7 +319,10 @@ wk.register({ -- Visual mode (with leader key) -- ----------------------------------- wk.register({ - a = {':EasyAlign', 'Range align'}, + a = { + name = 'Action', + a = {':EasyAlign', 'Range align'} + }, d = { name = 'DAP', diff --git a/home/.config/nvim/lua/modules/completion.lua b/home/.config/nvim/lua/modules/completion.lua index 1b1d181..0d136da 100644 --- a/home/.config/nvim/lua/modules/completion.lua +++ b/home/.config/nvim/lua/modules/completion.lua @@ -54,7 +54,7 @@ function M.cmp_conf() nvim_lsp = '[LSP]', -- cmp_tabnine = '[TN]', latex_symbols = '[TEX]', - tmux = '[TMUX]', + -- tmux = '[TMUX]', orgmode = '[ORG]' })[entry.source.name] @@ -121,7 +121,7 @@ function M.cmp_conf() -- {name = 'cmp_tabnine'}, {name = 'conjure'}, {name = 'latex_symbols'}, - {name = 'tmux'}, + -- {name = 'tmux'}, {name = 'orgmode'} } } diff --git a/home/.config/nvim/lua/modules/editor.lua b/home/.config/nvim/lua/modules/editor.lua index 3598ed5..ffe3278 100644 --- a/home/.config/nvim/lua/modules/editor.lua +++ b/home/.config/nvim/lua/modules/editor.lua @@ -66,6 +66,7 @@ function M.treesitter_conf() textobjects = { select = { enable = true, + lookahead = true, keymaps = { ['af'] = '@function.outer', ['if'] = '@function.inner', @@ -98,6 +99,34 @@ function M.treesitter_conf() } end +function M.iswap_conf() + require('iswap').setup { + -- The keys that will be used as a selection, in order + -- ('asdfghjklqwertyuiopzxcvbnm' by default) + -- keys = 'qwertyuiop', + + -- Grey out the rest of the text when making a selection + -- (enabled by default) + -- grey = 'disable', + + -- Highlight group for the sniping value (asdf etc.) + -- default 'Search' + -- hl_snipe = 'ErrorMsg', + + -- Highlight group for the visual selection of terms + -- default 'Visual' + -- hl_selection = 'WarningMsg', + + -- Highlight group for the greyed background + -- default 'Comment' + hl_grey = 'LineNr', + + -- Automatically swap with only two arguments + -- default nil + autoswap = true + } +end + function M.rainbow_conf() require('nvim-treesitter.configs').setup { rainbow = { diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index a93a7cc..ffb5ffa 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -228,11 +228,11 @@ end -- exclude = {'org'}, -- list of file types to exclude highlighting -- }, -- colors = { --- error = {'TodoError', 'Red'}, --- warning = {'TodoWarn', 'Yellow'}, --- info = {'TodoInfo', 'Blue'}, --- hint = {'TodoHint', 'Cyan'}, --- default = {'TodoDefault', 'White'} +-- error = {'LspDiagnosticsDefaultError', 'Red'}, +-- warning = {'LspDiagnosticsDefaultWarning', 'Yellow'}, +-- info = {'LspDiagnosticsDefaultInformation', 'Blue'}, +-- hint = {'LspDiagnosticsDefaultHint', 'Cyan'}, +-- default = {'Normal', 'White'} -- }, -- search = { -- command = 'rg', diff --git a/home/.config/nvim/lua/modules/pack.lua b/home/.config/nvim/lua/modules/pack.lua new file mode 100644 index 0000000..328928f --- /dev/null +++ b/home/.config/nvim/lua/modules/pack.lua @@ -0,0 +1,65 @@ +local fn, api = vim.fn, vim.api + +-- Require since we use 'packer' as opt +api.nvim_command('packadd packer.nvim') +local present, packer = pcall(require, 'packer') + +if not present then + local packer_dir = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim' + + print('Cloning packer ...') + -- remove packer_dir before cloning + fn.delete(packer_dir, 'rf') + fn.system {'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_dir} + api.nvim_command('packadd packer.nvim') + present, packer = pcall(require, 'packer') + + if present then + print('Pakcer cloned successfully.') + else + error('Git clone error for packer!') + end +end + +local util = require('packer.util') + +packer.init { + compile_path = util.join_paths(fn.stdpath('data'), 'site', 'plugin', 'packer_compiled.lua'), + auto_clean = true, + compile_on_sync = true, + auto_reload_compiled = true, + git = { + -- default_url_format = 'https://github.com/%s', + clone_timeout = 120 + }, + display = { + -- open_fn = function() + -- return util.float {border = 'single'} + -- end, + open_cmd = '60vnew \\[packer\\]', + working_sym = '⟳', + error_sym = '✗', + done_sym = '✓', + removed_sym = '-', + moved_sym = '→', + header_sym = '━', + show_all_info = true, + prompt_boder = 'single' + }, + -- profile = {enable = true, threshold = 1}, + luarocks = {python_cmd = 'python3'} +} + +-- Re-compile packer on config changed +_G.packer_compile_on_save = function() + local file = fn.expand('%:p') + local filename = fn.expand('%:p:t') + local config_dir = fn.stdpath('config') .. '/lua' + + if file:match(config_dir) and filename ~= 'pack.lua' then + vim.api.nvim_command('source | PackerCompile') + end +end +api.nvim_command('autocmd BufWritePost *.lua lua packer_compile_on_save()') + +return packer diff --git a/home/.config/nvim/lua/modules/tools.lua b/home/.config/nvim/lua/modules/tools.lua index 3caa6c0..3fd8303 100644 --- a/home/.config/nvim/lua/modules/tools.lua +++ b/home/.config/nvim/lua/modules/tools.lua @@ -46,6 +46,9 @@ function M.telescope_conf() require('telescope').load_extension('projects') require('telescope').load_extension('project') require('telescope').load_extension('fzf') + + -- wrap lines inside preview pane + vim.api.nvim_command('autocmd User TelescopePreviewerLoaded setlocal wrap') end function M.octo_conf() diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index c56b385..7ece32a 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -1,403 +1,404 @@ -local fn,api = vim.fn,vim.api -local packer_dir = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim' +local packer = require('modules.pack') -if fn.empty(fn.glob(packer_dir)) > 0 then - fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_dir}) - api.nvim_command('packadd packer.nvim') -end +-- This is recommended when using `luafile ` a lot +-- packer.reset() --- Require since we use 'packer' as opt -api.nvim_command [[packadd packer.nvim]] +return packer.startup(function(use) + use {'wbthomason/packer.nvim', opt = true} -return require('packer').startup( - function(use) - use {'wbthomason/packer.nvim', opt = true} + --------------------------------- + -- Plugins used by many others -- + --------------------------------- + use {'kyazdani42/nvim-web-devicons', module = 'nvim-web-devicons'} + use {'nvim-lua/plenary.nvim', module = 'plenary'} + use {'nvim-lua/popup.nvim', module = 'popup'} - --------------------------------- - -- Plugins used by many others -- - --------------------------------- - use {'kyazdani42/nvim-web-devicons', module = 'nvim-web-devicons'} - use {'nvim-lua/plenary.nvim', module = 'plenary'} - use {'nvim-lua/popup.nvim', module = 'popup'} - - -------- - -- UI -- - -------- - local ui = require('modules.ui') - use { - 'goolord/alpha-nvim', - event = 'VimEnter', - config = ui.dashboard_conf - } - use { - 'famiu/feline.nvim', - wants = 'nvim-web-devicons', - config = ui.statusline_conf - } - use { - 'akinsho/bufferline.nvim', - event = {'BufRead', 'BufNewFile'}, - config = ui.bufferline_conf - } - use { - 'kyazdani42/nvim-tree.lua', - cmd = 'NvimTreeToggle', - setup = ui.nvimtree_conf, - -- FIX: when all the options are migrated to setup() - config = function() - require('nvim-tree').setup { - open_on_setup = false, - auto_close = true, - hijack_cursor = true, - update_cwd = true, - lsp_diagnostics = true, - view = { - auto_resize = false - } + -------- + -- UI -- + -------- + local ui = require('modules.ui') + use { + 'goolord/alpha-nvim', + event = 'VimEnter', + config = ui.dashboard_conf + } + use { + 'famiu/feline.nvim', + wants = 'nvim-web-devicons', + config = ui.statusline_conf + } + use { + 'akinsho/bufferline.nvim', + event = {'BufRead', 'BufNewFile'}, + config = ui.bufferline_conf + } + use { + 'kyazdani42/nvim-tree.lua', + cmd = 'NvimTreeToggle', + setup = ui.nvimtree_conf, + -- FIX: when all the options are migrated to setup() + config = function() + require('nvim-tree').setup { + open_on_setup = false, + auto_close = true, + hijack_cursor = true, + update_cwd = true, + lsp_diagnostics = true, + view = { + auto_resize = false } - end - } - use { - 'folke/which-key.nvim', - event = 'VimEnter', - config = ui.whichkey_conf - } - use { - 'lewis6991/gitsigns.nvim', - event = {'BufRead', 'BufNewFile'}, - wants = 'plenary.nvim', - config = ui.gitsigns_conf - } + } + end + } + use { + 'folke/which-key.nvim', + event = 'VimEnter', + config = ui.whichkey_conf + } + use { + 'lewis6991/gitsigns.nvim', + event = {'BufRead', 'BufNewFile'}, + wants = 'plenary.nvim', + config = ui.gitsigns_conf + } - ------------ - -- Editor -- - ------------ - local editor = require('modules.editor') - use { - 'norcalli/nvim-colorizer.lua', - cmd = 'ColorizerToggle', - config = editor.colorizer_conf - } - use { - 'RRethy/vim-illuminate', - event = {'BufReadPre', 'BufNewFile'} - } - use { - 'lukas-reineke/indent-blankline.nvim', - after = 'nvim-treesitter', - config = editor.blankline_conf - } - use { -- TODO: config (lua -> fennel) + learn clojure, fennel, guile scheme - 'Olical/conjure', - ft = {'clojure', 'fennel', 'scheme'}, - requires = {{'Olical/aniseed', config = editor.aniseed_conf}} - } - use { - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate', - event = 'BufRead', - config = editor.treesitter_conf - } - use { - 'p00f/nvim-ts-rainbow', - after = 'nvim-treesitter', - -- Putting config into `treesitter_conf` doesn't work for some reason - config = editor.rainbow_conf - } - use { - 'romgrk/nvim-treesitter-context', - after = 'nvim-treesitter' - } - use { - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter' - } - use { - 'andymass/vim-matchup', - after = 'nvim-treesitter', - config = editor.matchup_conf - } - use { - 'machakann/vim-sandwich', - keys = 's' - } - use { - 'phaazon/hop.nvim', - cmd = {'HopChar1', 'HopChar2', 'HopWord', 'HopPattern', 'HopLine'}, - config = editor.hop_conf - } - use { - 'hrsh7th/vim-eft', - event = {'BufRead', 'BufNewFile'}, - setup = editor.eft_conf - } - use { - 'junegunn/vim-easy-align', - cmd = 'EasyAlign' - } - use { - 'terrortylor/nvim-comment', - keys = 'gc', - config = editor.comment_conf - } - use { - 'editorconfig/editorconfig-vim', - ft = {'go', 'rust', 'python', 'c', 'cpp', 'javascript', 'typescript', 'vim', 'zig'} - } - use { -- TODO: move to nvim-parinfer (lua) - 'eraserhd/parinfer-rust', - run = 'cargo build --release', - ft = {'clojure', 'lisp', 'scheme', 'fennel'} - } - use { - 'ahmedkhalf/project.nvim', - event = 'BufEnter', - config = editor.project_conf - } + ------------ + -- Editor -- + ------------ + local editor = require('modules.editor') + use { + 'norcalli/nvim-colorizer.lua', + cmd = 'ColorizerToggle', + config = editor.colorizer_conf + } + use { + 'RRethy/vim-illuminate', + event = {'BufReadPre', 'BufNewFile'} + } + use { + 'lukas-reineke/indent-blankline.nvim', + after = 'nvim-treesitter', + config = editor.blankline_conf + } + use { -- TODO: config (lua -> fennel) + learn clojure, fennel, guile scheme + 'Olical/conjure', + ft = {'clojure', 'fennel', 'scheme'}, + requires = {{'Olical/aniseed', config = editor.aniseed_conf}} + } + use { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + event = 'BufRead', + config = editor.treesitter_conf + } + use { + 'p00f/nvim-ts-rainbow', + after = 'nvim-treesitter', + -- Putting config into `treesitter_conf` doesn't work for some reason + config = editor.rainbow_conf + } + use { + 'romgrk/nvim-treesitter-context', + after = 'nvim-treesitter' + } + use { + 'nvim-treesitter/nvim-treesitter-textobjects', + after = 'nvim-treesitter' + } + use { + 'mizlan/iswap.nvim', + cmd = {'ISwapWith', 'ISwap'}, + wants = 'nvim-treesitter', + config = editor.iswap_conf + } + use { + 'andymass/vim-matchup', + after = 'nvim-treesitter', + config = editor.matchup_conf + } + use { + 'machakann/vim-sandwich', + keys = 's' + } + use { + 'phaazon/hop.nvim', + cmd = {'HopChar1', 'HopChar2', 'HopWord', 'HopPattern', 'HopLine'}, + config = editor.hop_conf + } + use { + 'hrsh7th/vim-eft', + event = {'BufRead', 'BufNewFile'}, + setup = editor.eft_conf + } + use { + 'junegunn/vim-easy-align', + cmd = 'EasyAlign' + } + use { + 'terrortylor/nvim-comment', + keys = 'gc', + config = editor.comment_conf + } + use { + 'editorconfig/editorconfig-vim', + ft = {'go', 'rust', 'python', 'c', 'cpp', 'javascript', 'typescript', 'vim', 'zig'} + } + use { -- TODO: move to nvim-parinfer (lua) + 'eraserhd/parinfer-rust', + run = 'cargo build --release', + ft = {'clojure', 'lisp', 'scheme', 'fennel'} + } + use { + 'ahmedkhalf/project.nvim', + event = 'BufEnter', + config = editor.project_conf + } - --------- - -- LSP -- - --------- - local lsp = require('modules.lsp') - use { -- TODO: scripts to install/update lsp servers - 'neovim/nvim-lspconfig', - event = 'BufReadPre', - wants = 'lsp_signature.nvim', - requires = {{'ray-x/lsp_signature.nvim', opt = true}}, - config = lsp.lsp_conf - } - use { - 'nanotee/sqls.nvim', - ft = {'sql', 'mysql', 'plsql'}, - wants = 'nvim-lspconfig', - config = lsp.sqls_conf - } - use { - 'folke/trouble.nvim', - cmd = {'Trouble', 'TroubleToggle', 'TroubleRefresh'}, - config = lsp.trouble_conf - } - -- use { -- FIX: conflict highlights with hop.nvim - -- 'folke/todo-comments.nvim', - -- wants = 'plenary.nvim', - -- event = 'BufRead', - -- config = lsp.comments_conf - -- } - use { - 'simrat39/symbols-outline.nvim', - cmd = {'SymbolsOutline', 'SymbolsOutlineOpen'}, - setup = lsp.outline_conf - } - use { -- TODO: scripts to install/update linters - 'mfussenegger/nvim-lint', - event = 'BufRead', - config = lsp.lint_conf - } - use { -- TODO: config, scripts to install/update dap servers - 'rcarriga/nvim-dap-ui', - event = 'BufReadPre', - wants = 'nvim-dap', - requires = {{'mfussenegger/nvim-dap', config = lsp.dap_conf, opt = true}}, - config = lsp.dapui_conf - } + --------- + -- LSP -- + --------- + local lsp = require('modules.lsp') + use { -- TODO: scripts to install/update lsp servers + 'neovim/nvim-lspconfig', + event = 'BufReadPre', + wants = 'lsp_signature.nvim', + requires = {{'ray-x/lsp_signature.nvim', opt = true}}, + config = lsp.lsp_conf + } + use { + 'nanotee/sqls.nvim', + ft = {'sql', 'mysql', 'plsql'}, + wants = 'nvim-lspconfig', + config = lsp.sqls_conf + } + use { + 'folke/trouble.nvim', + cmd = {'Trouble', 'TroubleToggle', 'TroubleRefresh'}, + config = lsp.trouble_conf + } + -- use { -- FIX: conflict highlights with hop.nvim + -- 'folke/todo-comments.nvim', + -- wants = 'plenary.nvim', + -- event = 'BufRead', + -- config = lsp.comments_conf + -- } + use { + 'simrat39/symbols-outline.nvim', + cmd = {'SymbolsOutline', 'SymbolsOutlineOpen'}, + setup = lsp.outline_conf + } + use { -- TODO: scripts to install/update linters + 'mfussenegger/nvim-lint', + event = 'BufRead', + config = lsp.lint_conf + } + use { -- TODO: config, scripts to install/update dap servers + 'rcarriga/nvim-dap-ui', + event = 'BufReadPre', + wants = 'nvim-dap', + requires = {{'mfussenegger/nvim-dap', config = lsp.dap_conf, opt = true}}, + config = lsp.dapui_conf + } - ---------------- - -- Completion -- - ---------------- - local completion = require('modules.completion') - use { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - wants = 'LuaSnip', - requires = {{ - 'L3MON4D3/LuaSnip', - wants = 'friendly-snippets', - requires = {{'rafamadriz/friendly-snippets', opt = true}}, - config = completion.snippets_conf, - opt = true - }}, - config = completion.cmp_conf - } - use {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp'} - use {'hrsh7th/cmp-path', after = 'nvim-cmp'} - use {'hrsh7th/cmp-buffer', after = 'nvim-cmp'} - -- use {'hrsh7th/cmp-calc', after = 'nvim-cmp'} - -- use {'f3fora/cmp-nuspell', after = 'nvim-cmp', rocks={'lua-nuspell'}} - use {'f3fora/cmp-spell', after = 'nvim-cmp'} - use {'hrsh7th/cmp-emoji', after = 'nvim-cmp'} - -- use {'ray-x/cmp-treesitter', after = {'nvim-cmp', 'nvim-treesitter'}} - use {'hrsh7th/cmp-nvim-lsp', after = {'nvim-cmp', 'nvim-lspconfig'}} - -- use { - -- 'tzachar/cmp-tabnine', - -- after = 'nvim-cmp', - -- run = './install.sh', - -- config = completion.tabnine_conf - -- } - use {'kdheepak/cmp-latex-symbols', after = {'nvim-cmp', 'vimtex'}} - use {'andersevenrud/compe-tmux', after = 'nvim-cmp', branch = 'cmp'} - use {'PaterJason/cmp-conjure', after = {'conjure', 'nvim-cmp'}} - use { - 'windwp/nvim-autopairs', - after = 'nvim-cmp', - config = completion.autopairs_conf - } - -- use { - -- 'ms-jpq/coq_nvim', - -- branch = 'coq', - -- event = 'InsertEnter', - -- run = ':COQdeps', - -- wants = 'coq.artifacts', - -- requires = {{'ms-jpq/coq.artifacts', branch = 'artifacts', opt = true}}, - -- setup = completion.coq_conf - -- } - use { - 'windwp/nvim-ts-autotag', - ft = { - 'html', 'javascript', 'javascriptreact', 'typescript', - 'typescriptreact', 'vue', 'svelte' - }, - wants = 'nvim-treesitter', - config = completion.autotag_conf - } + ---------------- + -- Completion -- + ---------------- + local completion = require('modules.completion') + use { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + wants = 'LuaSnip', + requires = {{ + 'L3MON4D3/LuaSnip', + wants = 'friendly-snippets', + requires = {{'rafamadriz/friendly-snippets', opt = true}}, + config = completion.snippets_conf, + opt = true + }}, + config = completion.cmp_conf + } + use {'saadparwaiz1/cmp_luasnip', after = 'nvim-cmp'} + use {'hrsh7th/cmp-path', after = 'nvim-cmp'} + use {'hrsh7th/cmp-buffer', after = 'nvim-cmp'} + -- use {'hrsh7th/cmp-calc', after = 'nvim-cmp'} + -- use {'f3fora/cmp-nuspell', after = 'nvim-cmp', rocks={'lua-nuspell'}} + use {'f3fora/cmp-spell', after = 'nvim-cmp'} + use {'hrsh7th/cmp-emoji', after = 'nvim-cmp'} + -- use {'ray-x/cmp-treesitter', after = {'nvim-cmp', 'nvim-treesitter'}} + use {'hrsh7th/cmp-nvim-lsp', after = {'nvim-cmp', 'nvim-lspconfig'}} + -- use { + -- 'tzachar/cmp-tabnine', + -- after = 'nvim-cmp', + -- run = './install.sh', + -- config = completion.tabnine_conf + -- } + use {'kdheepak/cmp-latex-symbols', after = {'nvim-cmp', 'vimtex'}} + -- use {'andersevenrud/compe-tmux', after = 'nvim-cmp', branch = 'cmp'} + use {'PaterJason/cmp-conjure', after = {'conjure', 'nvim-cmp'}} + use { + 'windwp/nvim-autopairs', + after = 'nvim-cmp', + config = completion.autopairs_conf + } + -- use { + -- 'ms-jpq/coq_nvim', + -- branch = 'coq', + -- event = 'InsertEnter', + -- run = ':COQdeps', + -- wants = 'coq.artifacts', + -- requires = {{'ms-jpq/coq.artifacts', branch = 'artifacts', opt = true}}, + -- setup = completion.coq_conf + -- } + use { + 'windwp/nvim-ts-autotag', + ft = { + 'html', 'javascript', 'javascriptreact', 'typescript', + 'typescriptreact', 'vue', 'svelte' + }, + wants = 'nvim-treesitter', + config = completion.autotag_conf + } - ----------- - -- Tools -- - ----------- - local tools = require('modules.tools') - use { -- TODO: watch out for fzf-lua - 'nvim-telescope/telescope.nvim', - cmd = 'Telescope', - wants = { - 'popup.nvim', - 'plenary.nvim', - 'telescope-symbols.nvim', - 'telescope-project.nvim', - 'telescope-fzf-native.nvim' - }, - requires = { - {'nvim-telescope/telescope-symbols.nvim', opt = true}, - {'nvim-telescope/telescope-project.nvim', opt = true}, - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true} - }, - config = tools.telescope_conf - } - use { -- TODO: colors + config - 'pwntester/octo.nvim', - cmd = 'Octo', - wants = 'telescope.nvim', - config = tools.octo_conf - } - use { - 'TimUntersberger/neogit', - cmd = 'Neogit', - wants = {'diffview.nvim', 'plenary.nvim'}, - requires = {{ - 'sindrets/diffview.nvim', - config = tools.diffview_conf, - opt = true - }}, - config = tools.neogit_conf - } - use { -- TODO: replace with code_runner.nvim - 'skywind3000/asynctasks.vim', - cmd = { - 'AsyncTask', - 'AsyncTaskEdit', - 'AsyncTaskList', - 'AsyncTaskMacro' - }, - wants = 'asyncrun.vim', - requires = {{ - 'skywind3000/asyncrun.vim', - setup = tools.asynctasks_conf, - opt = true - }} - } - use { - 'iamcco/markdown-preview.nvim', - run = 'cd app && yarn install', - ft = {'markdown', 'rmd'}, - config = tools.markdown_preview_conf - } - use { - 'turbio/bracey.vim', - run = 'npm install --prefix server', - cmd = 'Bracey' - } - use { - 'folke/zen-mode.nvim', - cmd = 'ZenMode', - wants = 'twilight.nvim', - requires = {{'folke/twilight.nvim', opt = true}}, - config = tools.zenmode_conf - } - use { -- shouldn't be lazy-loaded (global bindings don't work) - 'kristijanhusak/orgmode.nvim', - ft = 'org', - config = tools.orgmode_conf - } - use { -- TODO: config - 'lervag/vimtex', - ft = 'tex', - setup = tools.vimtext_conf - } - use { - 'windwp/nvim-spectre', - event = {'BufRead', 'BufNewFile'}, - wants = 'plenary.nvim', - config = tools.spectre_conf - } - use { - 'echuraev/translate-shell.vim', - cmd = {'Trans', 'TransSelectDirection'}, - config = tools.translate_conf - } - use { - 'mbbill/undotree', - cmd = 'UndotreeToggle', - setup = tools.undotree_conf - } - use { - 'akinsho/toggleterm.nvim', - cmd = 'ToggleTerm', - config = tools.toggleterm_conf - } - -- use { - -- 'gelguy/wilder.nvim', - -- run = ':UpdateRemotePlugins', - -- event = 'CmdlineEnter', - -- config = tools.wilder_conf - -- } - use { - 'karb94/neoscroll.nvim', - event = 'WinScrolled', - config = tools.neoscroll_conf - } - use { - 'michaelb/sniprun', - run = 'bash ./install.sh 1', - cmd = 'SnipRun', - config = tools.sniprun_conf - } - use { - 'NTBBloodbath/rest.nvim', - keys = {'RestNvim', 'RestNvimPreview', 'RestNvimLast'}, - wants = {'plenary.nvim', 'nvim-treesitter'}, - run = ':TSInstall http', - config = tools.rest_conf - } - use { -- TODO: move to formater.nvim - 'sbdchd/neoformat', - cmd = 'Neoformat' - } - use { - 'folke/persistence.nvim', - event = 'BufEnter', - config = tools.session_conf - } - -- use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking + ----------- + -- Tools -- + ----------- + local tools = require('modules.tools') + use { -- TODO: watch out for fzf-lua + 'nvim-telescope/telescope.nvim', + cmd = 'Telescope', + wants = { + 'popup.nvim', + 'plenary.nvim', + 'telescope-symbols.nvim', + 'telescope-project.nvim', + 'telescope-fzf-native.nvim' + }, + requires = { + {'nvim-telescope/telescope-symbols.nvim', opt = true}, + {'nvim-telescope/telescope-project.nvim', opt = true}, + {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true} + }, + config = tools.telescope_conf + } + use { -- TODO: colors + config + 'pwntester/octo.nvim', + cmd = 'Octo', + wants = 'telescope.nvim', + config = tools.octo_conf + } + use { + 'TimUntersberger/neogit', + cmd = 'Neogit', + wants = {'diffview.nvim', 'plenary.nvim'}, + requires = {{ + 'sindrets/diffview.nvim', + config = tools.diffview_conf, + opt = true + }}, + config = tools.neogit_conf + } + use { -- TODO: replace with code_runner.nvim + 'skywind3000/asynctasks.vim', + cmd = { + 'AsyncTask', + 'AsyncTaskEdit', + 'AsyncTaskList', + 'AsyncTaskMacro' + }, + wants = 'asyncrun.vim', + requires = {{ + 'skywind3000/asyncrun.vim', + setup = tools.asynctasks_conf, + opt = true + }} + } + use { + 'iamcco/markdown-preview.nvim', + run = 'cd app && yarn install', + ft = {'markdown', 'rmd'}, + config = tools.markdown_preview_conf + } + use { + 'turbio/bracey.vim', + run = 'npm install --prefix server', + cmd = 'Bracey' + } + use { + 'folke/zen-mode.nvim', + cmd = 'ZenMode', + wants = 'twilight.nvim', + requires = {{'folke/twilight.nvim', opt = true}}, + config = tools.zenmode_conf + } + use { -- shouldn't be lazy-loaded (global bindings don't work) + 'kristijanhusak/orgmode.nvim', + ft = 'org', + config = tools.orgmode_conf + } + use { -- TODO: config + 'lervag/vimtex', + ft = 'tex', + setup = tools.vimtext_conf + } + use { + 'windwp/nvim-spectre', + event = {'BufRead', 'BufNewFile'}, + wants = 'plenary.nvim', + config = tools.spectre_conf + } + use { + 'echuraev/translate-shell.vim', + cmd = {'Trans', 'TransSelectDirection'}, + config = tools.translate_conf + } + use { + 'mbbill/undotree', + cmd = 'UndotreeToggle', + setup = tools.undotree_conf + } + use { + 'akinsho/toggleterm.nvim', + cmd = 'ToggleTerm', + config = tools.toggleterm_conf + } + -- use { + -- 'gelguy/wilder.nvim', + -- run = ':UpdateRemotePlugins', + -- event = 'CmdlineEnter', + -- config = tools.wilder_conf + -- } + use { + 'karb94/neoscroll.nvim', + event = 'WinScrolled', + config = tools.neoscroll_conf + } + use { + 'michaelb/sniprun', + run = 'bash ./install.sh 1', + cmd = 'SnipRun', + config = tools.sniprun_conf + } + use { + 'NTBBloodbath/rest.nvim', + keys = {'RestNvim', 'RestNvimPreview', 'RestNvimLast'}, + wants = {'plenary.nvim', 'nvim-treesitter'}, + run = ':TSInstall http', + config = tools.rest_conf + } + use { -- TODO: move to formater.nvim + 'sbdchd/neoformat', + cmd = 'Neoformat' + } + use { + 'folke/persistence.nvim', + event = 'BufEnter', + config = tools.session_conf + } + use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking - -- TODO: dial.nvim, rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*, - -- nvim-bqf, nvim-comment-frame, nvim-revJ.lua - end -) + -- TODO: dial.nvim, rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*, + -- nvim-bqf, nvim-comment-frame, nvim-revJ.lua + + -- Install plugins if missing + packer.install() +end) diff --git a/home/.local/bin/doasedit b/home/.local/bin/doasedit new file mode 100755 index 0000000..3dc7f36 --- /dev/null +++ b/home/.local/bin/doasedit @@ -0,0 +1,104 @@ +#!/usr/bin/env sh + +# doasedit +# Link: git.io/doasedit + +# Dependencies: opendoas or doas + +# Author: Stanislav +# Description: doas equivalent to sudoedit. +# Licence: ISC +# Contribution: If you have some ideas, how to improve this script, feel free to make pull request or write an issue. + +# Tips: Use this script with enabled persistence in doas.conf file, like: +# +# `permit persist :wheel` +# +# Also make sure that your doas.conf is owned by root with read-only permissions, like: +# +# # chown -c root:root /path/to/doas.conf && chmod 0400 path/to/doas.conf +# + +# Throw error message. +err() { + printf "%s%s\n" "doasedit: " "${1}" >&2 + exit "${2}" +} + +# Catch arguments. +if [ -n "${2}" ]; then + err "expected only one argument" 1 +elif [ -z "${1}" ]; then + err "no file path provided" 2 +elif [ "$(id -u)" -eq 0 ]; then + err "doasedit: cannot be run as root" 3 +elif [ -d "${1}" ]; then + err "${1} is a directory" 4 +fi + +# Safe shell options. +set -eu + +# Reset doas password promt. If you want, feel free to comment this. +case "$(uname -s | tr '[:upper:]' '[:lower:]')" in + linux) doas -L ;; +esac + +# Absolute path to the source file (file for editing). +src="$(doas readlink -f "${1}")" + +# Filename for the source file. +filename="${src##*/}" + +# If filename have suffix then also use it for a temporary file. +# It's kinda useful for editors, that have plugins or something else for certain file extensions. +[ "$filename" = "${filename##*.}" ] && filename_ext="" || filename_ext=".${filename##*.}" + +# Be sure /tmp as tmp directory by setting TMPDIR env. +export TMPDIR=/tmp + +# Create a temporary directory. +tmp_d=$(mktemp -d) + +# Create a temporary file for the source file in a temporary directory. +tmp_f="${tmp_d}/${filename}$(xxd -l4 -ps /dev/urandom)${filename_ext}" + +# File writeability condition. +if [ -w "$src" ]; then + err "$filename: editing files in a writable directory is not permitted" 5 +fi + +# Other conditions: if file exist, readable, etc. +if [ -f "${src}" ] && [ ! -r "${src}" ]; then + doas cat "${src}" > "${tmp_f}" || err "the file is not readable" 6 +elif [ -r "${src}" ]; then + cat "${src}" > "${tmp_f}" || err "cannot transfer to content of the file to temporary one" 7 +elif [ ! -f "${src}" ]; then + # Grant .rw-r--r-- permission for newly created files by default owned by root. + :> "${tmp_f}" && doas chmod -R 0644 "${tmp_f}" || err "cannot create new file" 8 +else + err "unexpected script behaviour" 9 +fi + +# Create copy of the temporary file. +tmp_cf="${tmp_d}/${filename}$(xxd -l4 -ps /dev/urandom).copy" + +# Hooks for recursive removing of a temporary directory. +trap 'rm -rf ${tmp_d}' EXIT HUP QUIT TERM INT ABRT + +# Move the contents of a temporary file to its copy for later comparison. +cat "${tmp_f}" > "${tmp_cf}" + +# Editing the file by the user using the default editor, if not specified, the vi is used. +${EDITOR:-vi} "${tmp_f}" + +# Compare the temporary file and the temporary copy. +if cmp -s "${tmp_f}" "${tmp_cf}"; then + printf "%s\n" "doasedit: $filename unchanged" + exit 0 +else + # Replace the source file with temporary, repeats three times if it fails. + for doas_tries in $(seq 1 3); do doas cp -f "${tmp_f}" "${src}" && break; done + printf "%s\n" "doasedit: $filename changes are accepted" + exit 0 +fi diff --git a/home/.local/bin/pancomp b/home/.local/bin/pancomp deleted file mode 100755 index cc899ab..0000000 --- a/home/.local/bin/pancomp +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -if [ "$1" = "-h" ]; then - echo "Usage: pancomp [input_format] [input_file] [output_format] [output_file]" - exit 0 -fi - -if [ $# -ne 4 ]; then - echo "Bruh, I need 4 arguments." - exit 1 -fi - -pandoc \ - --pdf-engine=xelatex \ - -V 'mainfont:Iosevka Etoile' \ - -V 'sansfont:Iosevka Aile' \ - -V 'monofont:Iosevka' \ - -V 'geometry:margin=1in' \ - -f "$1" -t "$3" \ - -o "$4" "$2"