diff --git a/native_configs/neovim/init.lua b/native_configs/neovim/init.lua index b4b3979..046f2db 100644 --- a/native_configs/neovim/init.lua +++ b/native_configs/neovim/init.lua @@ -131,8 +131,8 @@ vim.api.nvim_create_autocmd({ "VimEnter" }, { }) -vim.g.gruvbox_contrast_dark="soft"; -vim.g.gruvbox_contrast_light="soft"; +vim.g.gruvbox_contrast_dark = "soft"; +vim.g.gruvbox_contrast_light = "soft"; vim.opt.ignorecase = true; vim.opt.smartcase = true; vim.opt.incsearch = true; @@ -159,7 +159,7 @@ vim.api.nvim_create_user_command('Dark', function(opts) vim.g.gruvbox_contrast_dark = contrast; vim.opt.background = "dark"; end, - {nargs = "?";}) + { nargs = "?"; }) vim.api.nvim_create_user_command('Light', function(opts) -- opts: {name, args: str, fargs: Splited, range, ...} @@ -168,7 +168,7 @@ vim.api.nvim_create_user_command('Light', function(opts) vim.g.gruvbox_contrast_light = contrast; vim.opt.background = "light"; end, - {nargs = "?";}) + { nargs = "?"; }) vim.opt.lazyredraw = true vim.opt.termguicolors = true @@ -176,7 +176,7 @@ vim.opt.cursorline = true -- some plugins misbehave when we do swap files vim.opt.swapfile = false vim.opt.backup = false -vim.opt.undodir = vim.fn.stdpath('state')..'/.vim/undodir' +vim.opt.undodir = vim.fn.stdpath('state') .. '/.vim/undodir' vim.opt.undofile = true vim.opt.completeopt = 'menuone,noselect' -- vim.opt.clipboard = "unnamedplus" @@ -246,6 +246,60 @@ vim.api.nvim_create_user_command( end, { nargs = 0 } ) + +-- `BufLoadFd {fd-args}` +-- WHAT: +-- Batch load the result of `fd ` into the buffer. +-- +-- WHY; +-- This is especially helpful if you want to collect LSP diagnostics in the +-- current repository: +-- +-- EXAMPLES: +-- `BufLoadFd -e ts -e tsx`: Loads all of tsserver-compatible in the current +-- root. Note that `fd` takes account of .gitignore (but not your Git's ignore config) +vim.api.nvim_create_user_command( + 'BufLoadFd', + function(opts) + local results = vim.fn.systemlist('fd ' .. opts["args"]) + for _k, v in pairs(results) do + vim.cmd("badd " .. v) + end + end, + { nargs = "*" } +) + +-- `CollectLspDiag {fd-args}` +-- WHAT: +-- Opens files matching fd-args search, and go back to your initial buffer +-- This effectively loads files onto your LSP so that you collect Lsp diagnostics. +-- To list diagnostics, maybe use `:Trouble` or similar commands +-- +-- WHY: +-- LSPs don't perform diagnostics to every file in the workspace, they are +-- lazily loaded. Sometimes, it's hard to reproduce the LSP diagnostics with +-- the compiler alone, this user command helps collecting all errors and +-- potentially filter the files that you want to ignore with an `fd` query. +-- +-- EXAMPLES: +-- `CollectLspDiag -e ts -e tsx`: Loads all Typescript files in the current root, +-- with account of `.gitignore` into "active buffer" for the LSP to diagnose. +vim.api.nvim_create_user_command( + 'CollectLspDiag', + function(opts) + --- @type string + local original_buf_path = vim.api.nvim_buf_get_name(0); + + local files = vim.fn.systemlist('fd ' .. opts["args"]) + for _k, file in pairs(files) do + vim.cmd("e " .. file) + end + + vim.cmd('e ' .. original_buf_path); + end, + { nargs = "*" } +) + vim.api.nvim_create_user_command( 'DoubleSpaces', function(opts) @@ -976,7 +1030,21 @@ require('lualine').setup { }, sections = { lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_b = { + 'branch', { + 'diff', source = function () + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed + } + end + end + }, + 'diagnostics' + }, lualine_c = { { 'filename', file_status = true, diff --git a/nix-conf/home-manager/base/neovim.nix b/nix-conf/home-manager/base/neovim.nix index f9677cd..dd295b7 100644 --- a/nix-conf/home-manager/base/neovim.nix +++ b/nix-conf/home-manager/base/neovim.nix @@ -43,7 +43,7 @@ let pkgs.fzf # file name fuzzy search pkgs.ripgrep # content fuzzy search pkgs.zk # Zettelkasten (limited support) - pkgs.fd # Required by a Telescope plugin (?) + pkgs.fd # Required by a Telescope plugin - fzf pkgs.stdenv.cc.cc.lib pkgs.rnix-lsp # doesn't work, Mason just installs it using cargo pkgs.rust4cargo @@ -56,8 +56,8 @@ let pkgs.python3Packages.pylint pkgs.python3Packages.flake8 # pkgs.ansible-lint - pkgs.python38Packages.ansible - pkgs.ansible-language-server + # pkgs.python38Packages.ansible + # pkgs.ansible-language-server # TODO: the devShell should provide rust-analyzer so that # cargo test builds binaries compatible with rust-analyzer diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 3b3abda..cde52e4 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -1,11 +1,15 @@ { nixConfig = { accept-flake-config = true; - experimental-features = "nix-command flakes"; + extra-experimental-features = "nix-command flakes"; extra-substituters = [ "https://nix-community.cachix.org" "https://cache.nixos.org" ]; + trusted-substituters = [ + "https://nix-community.cachix.org" + "https://cache.nixos.org" + ]; extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" @@ -149,7 +153,7 @@ # don't want to deal with GL stuffs on mac yet :/ base.graphics.useNixGL.defaultPackage = null; # NOTE: this actually does not exist - base.keepass.path = "/Users/hungtran/keepass.kdbx"; + base.keepass.path = "/Volumes/PersistentHotStorage/keepass.kdbx"; base.alacritty.font.size = 11.0; } nerd_font_module diff --git a/scripts/hm-switch.sh b/scripts/hm-switch.sh index b99a7ac..c124e2f 100755 --- a/scripts/hm-switch.sh +++ b/scripts/hm-switch.sh @@ -9,13 +9,13 @@ HOME_MANAGER_DIR="${SCRIPT_DIR}/../nix-conf/home-manager" # Manage nix.conf. Ideally, this should be done with snapshot-based version # and with preview on-the-spot, with some timeout -if [ -f /etc/nix/nix.conf ]; then - # managed nix.conf - BACKUP_FILE="/etc/nix/nix.conf.backup" - echo "overwriting /etc/nix/nix.conf. Please find latest backup in ${BACKUP_FILE}" - sudo cp /etc/nix/nix.conf ${BACKUP_FILE} - sudo cp "${HOME_MANAGER_DIR}/hwtr/nix.conf" /etc/nix/ -fi +# if [ -f /etc/nix/nix.conf ]; then +# # managed nix.conf +# BACKUP_FILE="/etc/nix/nix.conf.backup" +# echo "overwriting /etc/nix/nix.conf. Please find latest backup in ${BACKUP_FILE}" +# sudo cp /etc/nix/nix.conf ${BACKUP_FILE} +# sudo cp "${HOME_MANAGER_DIR}/hwtr/nix.conf" /etc/nix/ +# fi # Mason is bad: it puts binaries onto xdg.data # let's make mason starts fresh, just in case we introduce RPATH hacks