Updates to fish config, neovim config, vim config, and git config

Fish:
- Call ssh_agent_startup everytime (has its own conditions)
- Add Bun and pnpm bin folders to PATH and aliases
- Change additions to path to use fish_add_path
- Set LIBVA_DRIVER_NAME to nvidia

Neovim:
- Format init.lua
- Add Vue language server
- Change Noice config

Vim:
- Remove eslint and stylelint as fixers
- Add Vue linting/fixing
- Use wombat theme for lightline (gruvbox gone?)
- Add Lua & Markdown formatting
- Update vim-plug

Git:
- Remove --date-order from 'git lola' alias
This commit is contained in:
mitchell 2024-06-28 18:41:12 -04:00
parent 124ea84991
commit 3ad5bd6d2f
8 changed files with 246 additions and 191 deletions

View File

@ -10,10 +10,7 @@ function configure_fish
define_global_variables define_global_variables
import_sources $uname import_sources $uname
define_aliases $uname define_aliases $uname
ssh_agent_startup
if status is-login; and not set -qx SSH_CONNECTION
ssh_agent_startup
end
end end
configure_fish configure_fish

View File

@ -11,6 +11,8 @@ function define_aliases -a uname -d 'Defines aliases for commonly used commands'
alias age-d 'age --decrypt --identity ~/.secrets/id_ed25519' alias age-d 'age --decrypt --identity ~/.secrets/id_ed25519'
alias age-e 'age --armor --recipient (cat ~/.secrets/id_ed25519.pub)' alias age-e 'age --armor --recipient (cat ~/.secrets/id_ed25519.pub)'
alias age-k 'age --decrypt --identity ~/.secrets/id_ed25519 ~/.secrets/age_keys.age' alias age-k 'age --decrypt --identity ~/.secrets/id_ed25519 ~/.secrets/age_keys.age'
alias bb 'bun --bun'
alias pn 'pnpm'
switch "$uname" switch "$uname"
case 'Linux' case 'Linux'

View File

@ -14,17 +14,25 @@ function define_global_variables -d 'Defines all and exclusively globally export
set -gx GOPATH $HOME/code/go set -gx GOPATH $HOME/code/go
set -gx GOBIN $GOPATH/bin set -gx GOBIN $GOPATH/bin
set -gx BUN_INSTALL $HOME/.bun
set -gx LIBVIRT_DEFAULT_URI 'qemu:///system' set -gx LIBVIRT_DEFAULT_URI 'qemu:///system'
set -gx ANDROID_HOME $HOME/Android/Sdk set -gx ANDROID_HOME $HOME/Android/Sdk
set -gx PATH $PATH $GOBIN \ set -gx LIBVA_DRIVER_NAME nvidia
set -gx PNPM_HOME $HOME/.local/share/pnpm
fish_add_path $GOBIN \
$HOME/.local/bin \ $HOME/.local/bin \
$HOME/.pub-cache/bin \ $HOME/.pub-cache/bin \
$HOME/code/scripts \ $HOME/code/scripts \
$HOME/code/flutter/bin \ $HOME/code/flutter/bin \
$HOME/.cargo/bin \ $HOME/.cargo/bin \
$HOME/.dotnet/tools \ $HOME/.dotnet/tools \
$BUN_INSTALL/bin \
$PNPM_HOME \
$ANDROID_HOME/emulator \ $ANDROID_HOME/emulator \
$ANDROID_HOME/platform-tools \ $ANDROID_HOME/platform-tools \
$ANDROID_HOME/build-tools/31.0.0 \ $ANDROID_HOME/build-tools/31.0.0 \

View File

@ -1,5 +1,5 @@
function ssh_agent_startup -d 'Start ssh agent and set env vars' function ssh_agent_startup -d 'Start ssh agent and set env vars'
if test -z "$SSH_AUTH_SOCK"; or test -z "$SSH_AGENT_PID" if test -z "$SSH_AUTH_SOCK"; and test -z "$SSH_AGENT_PID"
eval (ssh-agent -c) >/dev/null 2>&1 eval (ssh-agent -c) >/dev/null 2>&1
end end
end end

View File

@ -9,122 +9,148 @@ vim.opt.guifont = { "JetBrainsMono Nerd Font", "h13" }
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>") vim.keymap.set("t", "<Esc>", "<C-\\><C-n>")
vim.api.nvim_create_autocmd("TermOpen", { vim.api.nvim_create_autocmd("TermOpen", {
pattern = "*", pattern = "*",
command = "set nonumber", command = "set nonumber",
}) })
require('twilight').setup() require("twilight").setup()
require('zen-mode').setup({ require("zen-mode").setup({
window = { window = {
backdrop = 1, backdrop = 1,
} },
}) })
require('symbols-outline').setup({ require("symbols-outline").setup({
autofold_depth = 2, autofold_depth = 2,
}) })
require('leap').add_default_mappings() require("leap").add_default_mappings()
require('noice').setup({ require("noice").setup({
lsp = { lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter** -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = { override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true, ["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, ["cmp.entry.get_documentation"] = true,
}, },
}, },
popupmenu = { presets = {
enabled = false, bottom_search = true, -- use a classic bottom cmdline for search
}, command_palette = true, -- position the cmdline and popupmenu together
presets = { long_message_to_split = true, -- long messages will be sent to a split
long_message_to_split = true, -- long messages will be sent to a split },
}, views = {
notify = {
replace = true,
merge = true,
},
},
}) })
require('treesitter-context').setup() require("treesitter-context").setup()
require('nvim-treesitter.configs').setup({ require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all" (the four listed parsers should always be installed) -- A list of parser names, or "all" (the four listed parsers should always be installed)
ensure_installed = { ensure_installed = {
"c", "c",
"lua", "lua",
"vim", "vim",
"help", "help",
"fish", "fish",
"typescript", "typescript",
"javascript", "javascript",
"go", "go",
"elixir", "elixir",
}, "vue",
"regex",
},
-- Automatically install missing parsers when entering buffer -- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true, auto_install = false,
highlight = { highlight = {
enable = true, enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time. -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights. -- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages -- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false, additional_vim_regex_highlighting = false,
}, },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
init_selection = "gnn", -- set to `false` to disable one of the mappings init_selection = "gnn", -- set to `false` to disable one of the mappings
node_incremental = "grn", node_incremental = "grn",
scope_incremental = "grc", scope_incremental = "grc",
node_decremental = "grm", node_decremental = "grm",
}, },
}, },
indent = { indent = {
enable = true enable = true,
} },
}) })
-- LSP Mappings. -- LSP Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions -- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true } local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts) vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
-- Use an on_attach function to only map the following keys -- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer -- after the language server attaches to the current buffer
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o> -- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings. -- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr } local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, bufopts) vim.keymap.set("n", "<leader>h", vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<leader>wl', function() vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts) end, bufopts)
vim.keymap.set('n', '<leader>m', vim.lsp.buf.code_action, bufopts) vim.keymap.set("n", "<leader>m", vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, bufopts) vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<leader>F', function() vim.lsp.buf.format { async = true } end, bufopts) vim.keymap.set("n", "<leader>F", function()
vim.lsp.buf.format({ async = true })
end, bufopts)
end end
local lspconfig = require "lspconfig" local lspconfig = require("lspconfig")
local coq = require "coq" local coq = require("coq")
local lsp_flags = { local lsp_flags = {
-- This is the default in Nvim 0.7+ -- This is the default in Nvim 0.7+
debounce_text_changes = 150, debounce_text_changes = 150,
} }
local servers = { 'tsserver', 'elixirls', 'gopls' } local vue_plugin_location = vim.fn.expand("$HOME/.bun/install/global/node_modules/@vue/language-server")
lspconfig.tsserver.setup(coq.lsp_ensure_capabilities({
on_attach = on_attach,
flags = lsp_flags,
init_options = {
plugins = {
{
name = "@vue/typescript-plugin",
location = vue_plugin_location,
languages = { "vue" },
},
},
},
filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue" },
}))
local servers = { "volar", "elixirls", "gopls", "pylsp" }
for _, lsp in ipairs(servers) do for _, lsp in ipairs(servers) do
lspconfig[lsp].setup(coq.lsp_ensure_capabilities({ lspconfig[lsp].setup(coq.lsp_ensure_capabilities({
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
})) }))
end end

View File

@ -9,7 +9,7 @@
llog = log --date=local llog = log --date=local
flog = log --pretty=fuller --decorate flog = log --pretty=fuller --decorate
lol = log --graph --decorate --oneline lol = log --graph --decorate --oneline
lola = log --graph --decorate --oneline --all --date-order lola = log --graph --decorate --oneline --all
blog = log origin/master... --left-right blog = log origin/master... --left-right
ds = diff --staged ds = diff --staged
amend = commit --amend -C HEAD amend = commit --amend -C HEAD

View File

@ -1,67 +1,36 @@
" vim-plug: Vim plugin manager " vim-plug: Vim plugin manager
" ============================ " ============================
" "
" Download plug.vim and put it in ~/.vim/autoload " 1. Download plug.vim and put it in 'autoload' directory
" "
" # Vim
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ " curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" "
" Edit your .vimrc " # Neovim
" sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
" "
" call plug#begin('~/.vim/plugged') " 2. Add a vim-plug section to your ~/.vimrc (or ~/.config/nvim/init.vim for Neovim)
" "
" " Make sure you use single quotes " call plug#begin()
" "
" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align " " List your plugins here
" Plug 'junegunn/vim-easy-align' " Plug 'tpope/vim-sensible'
" "
" " Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
"
" " Multiple Plug commands can be written in a single line using | separators
" Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
"
" " On-demand loading
" Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
"
" " Using a non-default branch
" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
"
" " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
" Plug 'fatih/vim-go', { 'tag': '*' }
"
" " Plugin options
" Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
"
" " Plugin outside ~/.vim/plugged with post-update hook
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
"
" " Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'
"
" " Initialize plugin system
" call plug#end() " call plug#end()
" "
" Then reload .vimrc and :PlugInstall to install plugins. " 3. Reload the file or restart Vim, then you can,
" "
" Plug options: " :PlugInstall to install plugins
" :PlugUpdate to update plugins
" :PlugDiff to review the changes from the last update
" :PlugClean to remove plugins no longer in the list
" "
"| Option | Description | " For more information, see https://github.com/junegunn/vim-plug
"| ----------------------- | ------------------------------------------------ |
"| `branch`/`tag`/`commit` | Branch/tag/commit of the repository to use |
"| `rtp` | Subdirectory that contains Vim plugin |
"| `dir` | Custom directory for the plugin |
"| `as` | Use different name for the plugin |
"| `do` | Post-update hook (string or funcref) |
"| `on` | On-demand loading: Commands or `<Plug>`-mappings |
"| `for` | On-demand loading: File types |
"| `frozen` | Do not update unless explicitly specified |
"
" More information: https://github.com/junegunn/vim-plug
" "
" "
" Copyright (c) 2017 Junegunn Choi " Copyright (c) 2024 Junegunn Choi
" "
" MIT License " MIT License
" "
@ -238,7 +207,6 @@ endfunction
function! plug#begin(...) function! plug#begin(...)
if a:0 > 0 if a:0 > 0
let s:plug_home_org = a:1
let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p')) let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p'))
elseif exists('g:plug_home') elseif exists('g:plug_home')
let home = s:path(g:plug_home) let home = s:path(g:plug_home)
@ -391,6 +359,9 @@ function! plug#end()
if !empty(types) if !empty(types)
augroup filetypedetect augroup filetypedetect
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
if has('nvim-0.5.0')
call s:source(s:rtp(plug), 'ftdetect/**/*.lua', 'after/ftdetect/**/*.lua')
endif
augroup END augroup END
endif endif
for type in types for type in types
@ -438,6 +409,9 @@ endfunction
function! s:load_plugin(spec) function! s:load_plugin(spec)
call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim') call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
if has('nvim-0.5.0')
call s:source(s:rtp(a:spec), 'plugin/**/*.lua', 'after/plugin/**/*.lua')
endif
endfunction endfunction
function! s:reload_plugins() function! s:reload_plugins()
@ -655,6 +629,9 @@ function! s:lod(names, types, ...)
let rtp = s:rtp(g:plugs[name]) let rtp = s:rtp(g:plugs[name])
for dir in a:types for dir in a:types
call s:source(rtp, dir.'/**/*.vim') call s:source(rtp, dir.'/**/*.vim')
if has('nvim-0.5.0') " see neovim#14686
call s:source(rtp, dir.'/**/*.lua')
endif
endfor endfor
if a:0 if a:0
if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2)) if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2))
@ -869,7 +846,7 @@ function! s:lastline(msg)
endfunction endfunction
function! s:new_window() function! s:new_window()
execute get(g:, 'plug_window', 'vertical topleft new') execute get(g:, 'plug_window', '-tabnew')
endfunction endfunction
function! s:plug_window_exists() function! s:plug_window_exists()
@ -1031,6 +1008,11 @@ function! s:is_updated(dir)
endfunction endfunction
function! s:do(pull, force, todo) function! s:do(pull, force, todo)
if has('nvim')
" Reset &rtp to invalidate Neovim cache of loaded Lua modules
" See https://github.com/junegunn/vim-plug/pull/1157#issuecomment-1809226110
let &rtp = &rtp
endif
for [name, spec] in items(a:todo) for [name, spec] in items(a:todo)
if !isdirectory(spec.dir) if !isdirectory(spec.dir)
continue continue
@ -1092,12 +1074,14 @@ endfunction
function! s:checkout(spec) function! s:checkout(spec)
let sha = a:spec.commit let sha = a:spec.commit
let output = s:git_revision(a:spec.dir) let output = s:git_revision(a:spec.dir)
let error = 0
if !empty(output) && !s:hash_match(sha, s:lines(output)[0]) if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : '' let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
let output = s:system( let output = s:system(
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir) \ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
let error = v:shell_error
endif endif
return output return [output, error]
endfunction endfunction
function! s:finish(pull) function! s:finish(pull)
@ -1158,7 +1142,7 @@ function! s:update_impl(pull, force, args) abort
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
\ remove(args, -1) : get(g:, 'plug_threads', 16) \ remove(args, -1) : get(g:, 'plug_threads', 16)
let managed = filter(copy(g:plugs), 's:is_managed(v:key)') let managed = filter(deepcopy(g:plugs), 's:is_managed(v:key)')
let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') :
\ filter(managed, 'index(args, v:key) >= 0') \ filter(managed, 'index(args, v:key) >= 0')
@ -1292,9 +1276,11 @@ function! s:update_finish()
if !pos if !pos
continue continue
endif endif
let out = ''
let error = 0
if has_key(spec, 'commit') if has_key(spec, 'commit')
call s:log4(name, 'Checking out '.spec.commit) call s:log4(name, 'Checking out '.spec.commit)
let out = s:checkout(spec) let [out, error] = s:checkout(spec)
elseif has_key(spec, 'tag') elseif has_key(spec, 'tag')
let tag = spec.tag let tag = spec.tag
if tag =~ '\*' if tag =~ '\*'
@ -1307,19 +1293,16 @@ function! s:update_finish()
endif endif
call s:log4(name, 'Checking out '.tag) call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir) let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
else let error = v:shell_error
let branch = s:git_origin_branch(spec)
call s:log4(name, 'Merging origin/'.s:esc(branch))
let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1'
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir)
endif endif
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && if !error && filereadable(spec.dir.'/.gitmodules') &&
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir)) \ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
call s:log4(name, 'Updating submodules. This may take a while.') call s:log4(name, 'Updating submodules. This may take a while.')
let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir) let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir)
let error = v:shell_error
endif endif
let msg = s:format_message(v:shell_error ? 'x': '-', name, out) let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
if v:shell_error if error
call add(s:update.errors, name) call add(s:update.errors, name)
call s:regress_bar() call s:regress_bar()
silent execute pos 'd _' silent execute pos 'd _'
@ -1382,7 +1365,9 @@ function! s:job_out_cb(self, data) abort
if !self.running || self.tick % len(s:jobs) == 0 if !self.running || self.tick % len(s:jobs) == 0
let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-') let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-')
let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines) let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines)
call s:log(bullet, self.name, result) if len(result)
call s:log(bullet, self.name, result)
endif
endif endif
endfunction endfunction
@ -1406,16 +1391,17 @@ function! s:nvim_cb(job_id, data, event) dict abort
\ s:job_cb('s:job_exit_cb', self, 0, a:data) \ s:job_cb('s:job_exit_cb', self, 0, a:data)
endfunction endfunction
function! s:spawn(name, cmd, opts) function! s:spawn(name, spec, queue, opts)
let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [''], let job = { 'name': a:name, 'spec': a:spec, 'running': 1, 'error': 0, 'lines': [''],
\ 'new': get(a:opts, 'new', 0) } \ 'new': get(a:opts, 'new', 0), 'queue': copy(a:queue) }
let Item = remove(job.queue, 0)
let argv = type(Item) == s:TYPE.funcref ? call(Item, [a:spec]) : Item
let s:jobs[a:name] = job let s:jobs[a:name] = job
if s:nvim if s:nvim
if has_key(a:opts, 'dir') if has_key(a:opts, 'dir')
let job.cwd = a:opts.dir let job.cwd = a:opts.dir
endif endif
let argv = a:cmd
call extend(job, { call extend(job, {
\ 'on_stdout': function('s:nvim_cb'), \ 'on_stdout': function('s:nvim_cb'),
\ 'on_stderr': function('s:nvim_cb'), \ 'on_stderr': function('s:nvim_cb'),
@ -1431,7 +1417,7 @@ function! s:spawn(name, cmd, opts)
\ 'Invalid arguments (or job table is full)'] \ 'Invalid arguments (or job table is full)']
endif endif
elseif s:vim8 elseif s:vim8
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"script": 0})')) let cmd = join(map(copy(argv), 'plug#shellescape(v:val, {"script": 0})'))
if has_key(a:opts, 'dir') if has_key(a:opts, 'dir')
let cmd = s:with_cd(cmd, a:opts.dir, 0) let cmd = s:with_cd(cmd, a:opts.dir, 0)
endif endif
@ -1451,27 +1437,34 @@ function! s:spawn(name, cmd, opts)
let job.lines = ['Failed to start job'] let job.lines = ['Failed to start job']
endif endif
else else
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [a:cmd, a:opts.dir] : [a:cmd])) let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
let job.error = v:shell_error != 0 let job.error = v:shell_error != 0
let job.running = 0 let job.running = 0
endif endif
endfunction endfunction
function! s:reap(name) function! s:reap(name)
let job = s:jobs[a:name] let job = remove(s:jobs, a:name)
if job.error if job.error
call add(s:update.errors, a:name) call add(s:update.errors, a:name)
elseif get(job, 'new', 0) elseif get(job, 'new', 0)
let s:update.new[a:name] = 1 let s:update.new[a:name] = 1
endif endif
let s:update.bar .= job.error ? 'x' : '='
let bullet = job.error ? 'x' : '-' let more = len(get(job, 'queue', []))
let bullet = job.error ? 'x' : more ? (job.new ? '+' : '*') : '-'
let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines) let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines)
call s:log(bullet, a:name, empty(result) ? 'OK' : result) if len(result)
call s:bar() call s:log(bullet, a:name, result)
endif
call remove(s:jobs, a:name) if !job.error && more
let job.spec.queue = job.queue
let s:update.todo[a:name] = job.spec
else
let s:update.bar .= job.error ? 'x' : '='
call s:bar()
endif
endfunction endfunction
function! s:bar() function! s:bar()
@ -1524,6 +1517,16 @@ function! s:update_vim()
call s:tick() call s:tick()
endfunction endfunction
function! s:checkout_command(spec)
let a:spec.branch = s:git_origin_branch(a:spec)
return ['git', 'checkout', '-q', a:spec.branch, '--']
endfunction
function! s:merge_command(spec)
let a:spec.branch = s:git_origin_branch(a:spec)
return ['git', 'merge', '--ff-only', 'origin/'.a:spec.branch]
endfunction
function! s:tick() function! s:tick()
let pull = s:update.pull let pull = s:update.pull
let prog = s:progress_opt(s:nvim || s:vim8) let prog = s:progress_opt(s:nvim || s:vim8)
@ -1538,13 +1541,18 @@ while 1 " Without TCO, Vim stack is bound to explode
let name = keys(s:update.todo)[0] let name = keys(s:update.todo)[0]
let spec = remove(s:update.todo, name) let spec = remove(s:update.todo, name)
let new = empty(globpath(spec.dir, '.git', 1)) let queue = get(spec, 'queue', [])
let new = empty(globpath(spec.dir, '.git', 1))
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') if empty(queue)
redraw call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
redraw
endif
let has_tag = has_key(spec, 'tag') let has_tag = has_key(spec, 'tag')
if !new if len(queue)
call s:spawn(name, spec, queue, { 'dir': spec.dir })
elseif !new
let [error, _] = s:git_validate(spec, 0) let [error, _] = s:git_validate(spec, 0)
if empty(error) if empty(error)
if pull if pull
@ -1555,7 +1563,11 @@ while 1 " Without TCO, Vim stack is bound to explode
if !empty(prog) if !empty(prog)
call add(cmd, prog) call add(cmd, prog)
endif endif
call s:spawn(name, cmd, { 'dir': spec.dir }) let queue = [cmd, split('git remote set-head origin -a')]
if !has_tag && !has_key(spec, 'commit')
call extend(queue, [function('s:checkout_command'), function('s:merge_command')])
endif
call s:spawn(name, spec, queue, { 'dir': spec.dir })
else else
let s:jobs[name] = { 'running': 0, 'lines': ['Already installed'], 'error': 0 } let s:jobs[name] = { 'running': 0, 'lines': ['Already installed'], 'error': 0 }
endif endif
@ -1570,7 +1582,7 @@ while 1 " Without TCO, Vim stack is bound to explode
if !empty(prog) if !empty(prog)
call add(cmd, prog) call add(cmd, prog)
endif endif
call s:spawn(name, extend(cmd, [spec.uri, s:trim(spec.dir)]), { 'new': 1 }) call s:spawn(name, spec, [extend(cmd, [spec.uri, s:trim(spec.dir)]), function('s:checkout_command'), function('s:merge_command')], { 'new': 1 })
endif endif
if !s:jobs[name].running if !s:jobs[name].running
@ -2269,7 +2281,10 @@ endfunction
function! s:with_cd(cmd, dir, ...) function! s:with_cd(cmd, dir, ...)
let script = a:0 > 0 ? a:1 : 1 let script = a:0 > 0 ? a:1 : 1
return printf('cd%s %s && %s', s:is_win ? ' /d' : '', plug#shellescape(a:dir, {'script': script}), a:cmd) let pwsh = s:is_powershell(&shell)
let cd = s:is_win && !pwsh ? 'cd /d' : 'cd'
let sep = pwsh ? ';' : '&&'
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
endfunction endfunction
function! s:system(cmd, ...) function! s:system(cmd, ...)
@ -2346,18 +2361,21 @@ function! s:git_validate(spec, check_branch)
\ current_branch, origin_branch) \ current_branch, origin_branch)
endif endif
if empty(err) if empty(err)
let [ahead, behind] = split(s:lastline(s:system([ let ahead_behind = split(s:lastline(s:system([
\ 'git', 'rev-list', '--count', '--left-right', \ 'git', 'rev-list', '--count', '--left-right',
\ printf('HEAD...origin/%s', origin_branch) \ printf('HEAD...origin/%s', origin_branch)
\ ], a:spec.dir)), '\t') \ ], a:spec.dir)), '\t')
if !v:shell_error && ahead if v:shell_error || len(ahead_behind) != 2
if behind let err = "Failed to compare with the origin. The default branch might have changed.\nPlugClean required."
else
let [ahead, behind] = ahead_behind
if ahead && behind
" Only mention PlugClean if diverged, otherwise it's likely to be " Only mention PlugClean if diverged, otherwise it's likely to be
" pushable (and probably not that messed up). " pushable (and probably not that messed up).
let err = printf( let err = printf(
\ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n" \ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n"
\ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', origin_branch, ahead, behind) \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', origin_branch, ahead, behind)
else elseif ahead
let err = printf("Ahead of origin/%s by %d commit(s).\n" let err = printf("Ahead of origin/%s by %d commit(s).\n"
\ .'Cannot update until local changes are pushed.', \ .'Cannot update until local changes are pushed.',
\ origin_branch, ahead) \ origin_branch, ahead)
@ -2389,7 +2407,7 @@ function! s:clean(force)
let errs = {} let errs = {}
let [cnt, total] = [0, len(g:plugs)] let [cnt, total] = [0, len(g:plugs)]
for [name, spec] in items(g:plugs) for [name, spec] in items(g:plugs)
if !s:is_managed(name) if !s:is_managed(name) || get(spec, 'frozen', 0)
call add(dirs, spec.dir) call add(dirs, spec.dir)
else else
let [err, clean] = s:git_validate(spec, 1) let [err, clean] = s:git_validate(spec, 1)
@ -2637,8 +2655,8 @@ function! s:preview_commit()
return return
endif endif
if exists('g:plug_pwindow') && !s:is_preview_window_open() if !s:is_preview_window_open()
execute g:plug_pwindow execute get(g:, 'plug_pwindow', 'vertical rightbelow new')
execute 'e' title execute 'e' title
else else
execute 'pedit' title execute 'pedit' title

12
.vimrc
View File

@ -131,13 +131,14 @@ highlight Normal ctermbg=None
let g:ackprg = 'ag --nogroup --nocolor --column --hidden' let g:ackprg = 'ag --nogroup --nocolor --column --hidden'
let g:lightline = { let g:lightline = {
\ 'colorscheme': 'gruvbox', \ 'colorscheme': 'wombat',
\ } \ }
let g:ale_linters = { let g:ale_linters = {
\ 'javascript': ['eslint', 'stylelint'], \ 'javascript': ['eslint', 'stylelint'],
\ 'go': ['golint', 'go vet'], \ 'go': ['golint', 'go vet'],
\ 'typescript': ['eslint', 'stylelint'], \ 'typescript': ['eslint', 'stylelint'],
\ 'vue': ['eslint', 'stylelint'],
\ 'make': ['checkmake'], \ 'make': ['checkmake'],
\ 'proto': ['protoc-gen-lint'], \ 'proto': ['protoc-gen-lint'],
\ 'dockerfile': ['hadolint'], \ 'dockerfile': ['hadolint'],
@ -157,18 +158,21 @@ let g:ale_linters = {
let g:ale_fixers = { let g:ale_fixers = {
\ 'go': ['goimports', 'remove_trailing_lines', 'trim_whitespace'], \ 'go': ['goimports', 'remove_trailing_lines', 'trim_whitespace'],
\ 'graphql': ['prettier'], \ 'graphql': ['prettier'],
\ 'javascript': ['eslint', 'prettier'], \ 'javascript': ['prettier'],
\ 'typescript': ['eslint', 'prettier'], \ 'typescript': ['prettier'],
\ 'css': ['prettier', 'stylelint'], \ 'vue': ['prettier'],
\ 'css': ['prettier'],
\ 'yaml': ['prettier'], \ 'yaml': ['prettier'],
\ 'json': ['prettier'], \ 'json': ['prettier'],
\ 'dart': ['dartfmt'], \ 'dart': ['dartfmt'],
\ 'html': ['prettier'], \ 'html': ['prettier'],
\ 'markdown': ['prettier'],
\ 'make': ['remove_trailing_lines', 'trim_whitespace'], \ 'make': ['remove_trailing_lines', 'trim_whitespace'],
\ 'elixir': ['mix_format'], \ 'elixir': ['mix_format'],
\ 'terraform': ['terraform'], \ 'terraform': ['terraform'],
\ 'ruby': ['rubocop'], \ 'ruby': ['rubocop'],
\ 'python': ['black'], \ 'python': ['black'],
\ 'lua': ['stylua'],
\ } \ }
let g:ale_linters_explicit = 1 let g:ale_linters_explicit = 1