From e2f40a7be7a85a9fcdbe8e34d42e6ac79da073aa Mon Sep 17 00:00:00 2001 From: Lynda Wang Date: Sat, 25 Jul 2020 19:39:09 -0400 Subject: [PATCH] Improve OSX setup --- aliases | 2 +- bin/compress-video | 2 +- bin/symbolic-link | 2 +- bin/sync-android-chrome-tabs | 2 +- bin/update-msys-shell | 2 +- bin/vim-pull | 2 +- bin/vim-push | 2 +- install | 68 +- osx/install | 75 ++ osx/install.sh | 52 -- osx/pre_install | 54 ++ osx/readme.md | 14 - script_helpers/all.sh | 2 +- script_helpers/clang.sh | 2 +- script_helpers/core.sh | 2 +- script_helpers/file_ops.sh | 17 +- script_helpers/msvc.sh | 2 +- script_helpers/platform.sh | 2 +- script_helpers/printing.sh | 2 +- vim/autoload/plug.vim | 1369 +++++++++++++++++++++++++--------- vim/templates/skeleton.sh | 2 +- vimrc | 346 ++++----- windows/readme.md | 2 +- zlogin | 18 +- zprofile | 1 - zshenv | 21 +- zshrc | 15 +- 27 files changed, 1378 insertions(+), 702 deletions(-) mode change 100644 => 100755 install create mode 100755 osx/install delete mode 100755 osx/install.sh create mode 100755 osx/pre_install delete mode 100644 osx/readme.md delete mode 100644 zprofile diff --git a/aliases b/aliases index 57dbcc7..0ab6dbc 100644 --- a/aliases +++ b/aliases @@ -39,7 +39,6 @@ abort() { reload() { if [[ $platform == 'Linux' || $platform == 'Darwin' ]]; then - #source ~/.zshrc test -f ~/.aliases && . ~/.aliases else test -f ~/.aliases && . ~/.aliases @@ -445,6 +444,7 @@ alias pdot='cd ~/.private-dotfiles' alias duh='du -csh' alias exp='explorer .' alias f='fg' +alias grep='grep -n --color ' alias history='fc -l 1' alias histroy='history' alias irb='irb --readline -r irb/completion' diff --git a/bin/compress-video b/bin/compress-video index 9bcc335..fe75a33 100644 --- a/bin/compress-video +++ b/bin/compress-video @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if which tput >/dev/null 2>&1; then ncolors=$(tput colors) diff --git a/bin/symbolic-link b/bin/symbolic-link index 960de1b..f0c2f82 100644 --- a/bin/symbolic-link +++ b/bin/symbolic-link @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash source "$HOME/.dotfiles/script_helpers/all.sh" diff --git a/bin/sync-android-chrome-tabs b/bin/sync-android-chrome-tabs index f1ac74b..99ac980 100644 --- a/bin/sync-android-chrome-tabs +++ b/bin/sync-android-chrome-tabs @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if which tput >/dev/null 2>&1; then ncolors=$(tput colors) diff --git a/bin/update-msys-shell b/bin/update-msys-shell index 433db0b..3e26bb0 100644 --- a/bin/update-msys-shell +++ b/bin/update-msys-shell @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash source "$HOME/.dotfiles/script_helpers/printing.sh" source "$HOME/.dotfiles/script_helpers/platform.sh" diff --git a/bin/vim-pull b/bin/vim-pull index eb93b95..d5a3904 100644 --- a/bin/vim-pull +++ b/bin/vim-pull @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copies vim data from the home directory to the dotfiles repo. diff --git a/bin/vim-push b/bin/vim-push index a06ad10..f2952bf 100644 --- a/bin/vim-push +++ b/bin/vim-push @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copies vim data from the dotfiles repo to the home directory. diff --git a/install b/install old mode 100644 new mode 100755 index 5ce294a..5e03a2c --- a/install +++ b/install @@ -1,4 +1,15 @@ -#!/bin/bash +#!/usr/bin/env bash + +platform=`uname` + +if [[ $platform == 'Darwin' ]]; then + if ! command -v brew &>/dev/null + then + # We need to update bash, so we'll start with setting up homebrew. + ./osx/pre_install + exit + fi +fi source "script_helpers/printing.sh" source "script_helpers/core.sh" @@ -6,9 +17,10 @@ source "script_helpers/platform.sh" source "script_helpers/file_ops.sh" cwd=$PWD -platform=`uname` confirm_link=0 os_is_windows is_windows +os_is_macos is_macos +os_is_linux is_linux if [[ $is_windows -eq 1 ]]; then # Check for admin permissions. @@ -26,32 +38,34 @@ set -e #################################################################################################### setup_zsh() { - printf "Setting up zsh...\n" + printf "Setting up zsh...\n" - sudo apt install zsh - - TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)') - if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then - if hash chsh >/dev/null 2>&1; then - printf "\n${BLUE}Changing the default shell to zsh${NORMAL}\n" - chsh -s $(grep /zsh$ /etc/shells | tail -1) - else - printf "\n${RED}Unable to change the shell because this system does not have chsh.\n" - printf "${BLUE}If this is Windows then you probably want to run the bash installer.${NORMAL}\n" + if [[ $is_linux -eq 1 ]]; then + sudo apt install zsh fi - fi - FILES=() - FILES+=('zsh') - FILES+=('zshrc') - FILES+=('zshenv') - FILES+=('zlogin') - FILES+=('zprofile') + TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)') + if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then + if hash chsh >/dev/null 2>&1; then + printf "\n${BLUE}Changing the default shell to zsh${NORMAL}\n" + chsh -s $(grep /zsh$ /etc/shells | tail -1) + else + printf "\n${RED}Unable to change the shell because this system does not have chsh.\n" + printf "${BLUE}If this is Windows then you probably want to run the bash installer.${NORMAL}\n" + fi + fi - for file in "${FILES[@]}" - do - setup_file "$file" - done + setup_dir .dotfiles/zsh .zsh + + FILES=() + FILES+=('zshrc') + FILES+=('zshenv') + FILES+=('zlogin') + + for file in "${FILES[@]}" + do + setup_file .dotfiles/$file .$file + done } #################################################################################################### @@ -96,9 +110,9 @@ if [[ $is_windows -eq 0 ]]; then setup_zsh fi -if [[ $platform == 'Darwin' ]]; then - printf "\n${BOLD}Running the OS X installer${NORMAL}\n" - ./osx/install.sh +if [[ $is_macos -eq 1 ]]; then + printf "\n${BOLD}Running the MacOS installer${NORMAL}\n" + $cwd/osx/install fi popd "$HOME" &>/dev/null diff --git a/osx/install b/osx/install new file mode 100755 index 0000000..5f2dcce --- /dev/null +++ b/osx/install @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) +fi +if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + BOLD="$(tput bold)" + NORMAL="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + BOLD="" + NORMAL="" +fi + +set -e + +printf "Installing env...\n" +ln -sf $HOME/.dotfiles/osx/env.platform $HOME/.env.platform + +printf "Installing Git customizations...\n" +ln -sf $HOME/.dotfiles/osx/gitconfig.platform $HOME/.gitconfig.platform + +#----------------------------------- +# Homebrew packages +#----------------------------------- + +printf "Installing Homebrew...\n" + +brew_packages=( + 'openssl' + 'wget' + 'git' + 'rlwrap' + 'cmake' + 'vim' + 'sdl' + 'tree' +) +brew tap homebrew/core +for package in "${brew_packages[@]}" +do + printf "Installing $package...\n" + ret=$(brew list | awk /$package/) + if [[ $ret == $package ]]; then + printf "${YELLOW}Already installed!${NORMAL}\n" + else + eval "brew install $package" + printf \n + fi +done + +# We have issues downloading Rust on 10.11 with the patched Homebrew checkout +# so we'll install it using their script. +bash -c "$(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs)" + +# For Vim search +cargo install ripgrep + +# The homebrew core ctags package is very old. +brew install --HEAD universal-ctags/universal-ctags/universal-ctags + +printf "\n${YELLOW}If you haven't already installed the Xcode dev tools then do so now by installing Xcode from the App Store:${NORMAL}\n" +printf "When that finishes open a terminal and run the following:\n" +printf " 1. ${YELLOW}sudo xcode-select --install${NORMAL}\n" +printf " 2. ${YELLOW}sudo xcodebuild -license${NORMAL}\n" +printf " 3. ${YELLOW}sudo xcode-select -s /Applications/Xcode.app/Contents/Developer${NORMAL}\n" + +printf "\n${BOLD}Finished setting up OS X${NORMAL}\n" diff --git a/osx/install.sh b/osx/install.sh deleted file mode 100755 index 86e0d60..0000000 --- a/osx/install.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -source "../script_helpers/printing.sh" - -set -e - -printf "Installing env...\n" -ln -sf $HOME/.dotfiles/osx/env.platform $HOME/.env.platform - -printf "Installing git customizations...\n" -ln -sf $HOME/.dotfiles/osx/gitconfig.platform $HOME/.gitconfig.platform - -brew tap homebrew/core - -printf "Installing xquartz..." -#brew cask install xquartz - -brew_packages=( - 'tree' - 'openssl' - 'git' -# 'xclip' - 'rlwrap' - 'cmake' - 'pkg-config' - 'vim' - 'the_silver_searcher' - 'selecta' -# 'rust' -# 'go' - 'sdl') - -for package in "${brew_packages[@]}" -do - printf "Installing $package..." - ret=$(brew list | awk /$package/) - if [[ $ret == $package ]]; then - printf "${YELLOW}already installed!${NORMAL}\n" - else - eval "brew install $package" - printf \n - fi -done - -printf "\n${YELLOW}Now you must install Xcode.${NORMAL}\n" -printf "Open the App Store and install the software.\n" -printf "When that finishes open a terminal and run the following:\n" -printf " 1. ${YELLOW}sudo xcode-select --install${NORMAL}\n" -printf " 2. ${YELLOW}sudo xcodebuild -license${NORMAL}\n" -printf " 3. ${YELLOW}sudo xcode-select -s /Applications/Xcode.app/Contents/Developer${NORMAL}\n" - -printf "\n${BOLD}Finished setting up OS X${NORMAL}\n" diff --git a/osx/pre_install b/osx/pre_install new file mode 100755 index 0000000..250a489 --- /dev/null +++ b/osx/pre_install @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) +fi +if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + BLUE="$(tput setaf 4)" + BOLD="$(tput bold)" + NORMAL="$(tput sgr0)" +else + RED="" + GREEN="" + YELLOW="" + BLUE="" + BOLD="" + NORMAL="" +fi + +set -e + +printf "Installing Homebrew...\n" + +# OSX 10.11 and earlier will issue certificate errors when Homebrew attempts to download packages +# with curl. Detect if we're running on 10.11 or earlier and if so use a fork that passes the +# --insecure option to curl. +kernel_major="$(uname -r | sed 's/\..*//')" +case $kernel_major in + 15 | 14 | 13) download_patched_homebrew=1 ;; + *) download_patched_homebrew=0 ;; +esac + +if [[ $download_patched_homebrew -eq 1 ]]; then + printf "${BOLD}Current MacOS kernel ${NORMAL}${YELLOW}$(uname -r)${NORMAL}${BOLD} requires a patched version of Homebrew...${NORMAL}\n" + bash -c "$(curl -fsSL https://raw.githubusercontent.com/sir-pinecone/brew/master/install.sh)" +else + bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" +fi + +brew tap homebrew/core + +printf "\nInstalling bash...\n" +ret=$(brew list | awk /$package/) +if [[ $ret == $package ]]; then + printf "${YELLOW}Already installed!${NORMAL}\n" +else + eval "brew install bash" + printf "\n${YELLOW}Finished installing updated version of bash.\nYou must now enable it. Run:${NORMAL}\n" + printf " ${BOLD}sudo vim /etc/shells${NORMAL}\n" + printf "${YELLOW}And add ${NORMAL}${BOLD}/usr/local/bin/bash${NORMAL}${YELLOW} to the end of the list. After that close your terminal and re-run the dotfiles install script.${NORMAL}\n" +fi + diff --git a/osx/readme.md b/osx/readme.md deleted file mode 100644 index 01032f9..0000000 --- a/osx/readme.md +++ /dev/null @@ -1,14 +0,0 @@ -# OSX - -## Setting up Ruby - -* Install rvm -* Install bundler -* Install Ruby Docs - gem install rdoc-data - rdoc-data --install - gem rdoc --all --overwrite - -## Setup Keyboard - -Map to in System Preferences -> Keyboard -> Modifier Keys. Now can leave insert mode. diff --git a/script_helpers/all.sh b/script_helpers/all.sh index ca07a48..24b6c5b 100644 --- a/script_helpers/all.sh +++ b/script_helpers/all.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash source_helpers="$HOME/.dotfiles/script_helpers" source "$source_helpers/printing.sh" diff --git a/script_helpers/clang.sh b/script_helpers/clang.sh index e8ce9f0..0a9c18e 100644 --- a/script_helpers/clang.sh +++ b/script_helpers/clang.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #--------------------------------------------------------------------------------------------------- # API diff --git a/script_helpers/core.sh b/script_helpers/core.sh index a78bb79..deff54c 100644 --- a/script_helpers/core.sh +++ b/script_helpers/core.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Requires the printing.sh helper to be sourced. diff --git a/script_helpers/file_ops.sh b/script_helpers/file_ops.sh index 28abcfb..9314009 100644 --- a/script_helpers/file_ops.sh +++ b/script_helpers/file_ops.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Requires the printing.sh helper to be sourced. # Requires the platform.sh helper to be sourced. @@ -165,12 +165,14 @@ link_file() { echo "expand_symlinks? $expand_symlinks" fi - if [[ $expand_symlinks -eq 1 ]]; then - source_path=$(expand_path "$source_path") - dest_path=$(expand_path "$dest_path") - else - source_path=$(_clean_link_file_path "$source_path") - dest_path=$(_clean_link_file_path "$dest_path") + if [[ $is_windows -eq 1 ]]; then + if [[ $expand_symlinks -eq 1 ]]; then + source_path=$(expand_path "$source_path") + dest_path=$(expand_path "$dest_path") + else + source_path=$(_clean_link_file_path "$source_path") + dest_path=$(_clean_link_file_path "$dest_path") + fi fi if [[ $debug -eq 1 ]]; then @@ -210,6 +212,7 @@ link_file() { echo Link cmd:: $link_cmd fi + printf "${BOLD}*${NORMAL} ${YELLOW}Linking '$source_path'${NORMAL} to ${YELLOW}'$dest_path'${NORMAL}\n" eval $link_cmd } diff --git a/script_helpers/msvc.sh b/script_helpers/msvc.sh index 5faa076..1acbf20 100644 --- a/script_helpers/msvc.sh +++ b/script_helpers/msvc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #--------------------------------------------------------------------------------------------------- # API diff --git a/script_helpers/platform.sh b/script_helpers/platform.sh index 892f71c..d23d638 100644 --- a/script_helpers/platform.sh +++ b/script_helpers/platform.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash uname_s="$(uname -s)" case "${uname_s}" in diff --git a/script_helpers/printing.sh b/script_helpers/printing.sh index 9c33710..73c5b91 100644 --- a/script_helpers/printing.sh +++ b/script_helpers/printing.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if which tput >/dev/null 2>&1; then ncolors=$(tput colors) diff --git a/vim/autoload/plug.vim b/vim/autoload/plug.vim index c682537..7914bfe 100644 --- a/vim/autoload/plug.vim +++ b/vim/autoload/plug.vim @@ -11,22 +11,26 @@ " call plug#begin('~/.vim/plugged') " " " Make sure you use single quotes -" Plug 'junegunn/seoul256.vim' +" +" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align " Plug 'junegunn/vim-easy-align' " -" " Group dependencies, vim-snippets depends on ultisnips +" " 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 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " -" " Using git URL -" Plug 'https://github.com/junegunn/vim-github-dashboard.git' -" " " Using a non-master 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' } " @@ -36,14 +40,28 @@ " " Unmanaged plugin (manually installed and updated) " Plug '~/my-prototype-plugin' " -" " Add plugins to &runtimepath +" " Initialize plugin system " call plug#end() " " Then reload .vimrc and :PlugInstall to install plugins. -" Visit https://github.com/junegunn/vim-plug for more information. +" +" Plug options: +" +"| Option | Description | +"| ----------------------- | ------------------------------------------------ | +"| `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 ``-mappings | +"| `for` | On-demand loading: File types | +"| `frozen` | Do not update unless explicitly specified | +" +" More information: https://github.com/junegunn/vim-plug " " -" Copyright (c) 2015 Junegunn Choi +" Copyright (c) 2017 Junegunn Choi " " MIT License " @@ -78,9 +96,16 @@ let s:plug_src = 'https://github.com/junegunn/vim-plug.git' let s:plug_tab = get(s:, 'plug_tab', -1) let s:plug_buf = get(s:, 'plug_buf', -1) let s:mac_gui = has('gui_macvim') && has('gui_running') -let s:is_win = has('win32') || has('win64') -let s:nvim = has('nvim') && exists('*jobwait') && !s:is_win -let s:me = resolve(expand(':p')) +let s:is_win = has('win32') +let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win) +let s:vim8 = has('patch-8.0.0039') && exists('*job_start') +if s:is_win && &shellslash + set noshellslash + let s:me = resolve(expand(':p')) + set shellslash +else + let s:me = resolve(expand(':p')) +endif let s:base_spec = { 'branch': 'master', 'frozen': 0 } let s:TYPE = { \ 'string': type(''), @@ -91,10 +116,42 @@ let s:TYPE = { let s:loaded = get(s:, 'loaded', {}) let s:triggers = get(s:, 'triggers', {}) +if s:is_win + function! s:plug_call(fn, ...) + let shellslash = &shellslash + try + set noshellslash + return call(a:fn, a:000) + finally + let &shellslash = shellslash + endtry + endfunction +else + function! s:plug_call(fn, ...) + return call(a:fn, a:000) + endfunction +endif + +function! s:plug_getcwd() + return s:plug_call('getcwd') +endfunction + +function! s:plug_fnamemodify(fname, mods) + return s:plug_call('fnamemodify', a:fname, a:mods) +endfunction + +function! s:plug_expand(fmt) + return s:plug_call('expand', a:fmt, 1) +endfunction + +function! s:plug_tempname() + return s:plug_call('tempname') +endfunction + function! plug#begin(...) if a:0 > 0 let s:plug_home_org = a:1 - let home = s:path(fnamemodify(expand(a:1), ':p')) + let home = s:path(s:plug_fnamemodify(s:plug_expand(a:1), ':p')) elseif exists('g:plug_home') let home = s:path(g:plug_home) elseif !empty(&rtp) @@ -102,6 +159,9 @@ function! plug#begin(...) else return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.') endif + if s:plug_fnamemodify(home, ':t') ==# 'plugin' && s:plug_fnamemodify(home, ':h') ==# s:first_rtp + return s:err('Invalid plug home. '.home.' is a standard Vim runtime path and is not allowed.') + endif let g:plug_home = home let g:plugs = {} @@ -113,17 +173,27 @@ function! plug#begin(...) endfunction function! s:define_commands() - command! -nargs=+ -bar Plug call s:add() + command! -nargs=+ -bar Plug call plug#() if !executable('git') - return s:err('`git` executable not found. vim-plug requires git.') + return s:err('`git` executable not found. Most commands will not be available. To suppress this message, prepend `silent!` to `call plug#begin(...)`.') endif - command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('' == '!', []) - command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('' == '!', []) - command! -nargs=0 -bar -bang PlugClean call s:clean('' == '!') + if has('win32') + \ && &shellslash + \ && (&shell =~# 'cmd\(\.exe\)\?$' || &shell =~# 'powershell\(\.exe\)\?$') + return s:err('vim-plug does not support shell, ' . &shell . ', when shellslash is set.') + endif + if !has('nvim') + \ && (has('win32') || has('win32unix')) + \ && !has('multi_byte') + return s:err('Vim needs +multi_byte feature on Windows to run shell commands. Enable +iconv for best results.') + endif + command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(0, []) + command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(0, []) + command! -nargs=0 -bar -bang PlugClean call s:clean(0) command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif command! -nargs=0 -bar PlugStatus call s:status() command! -nargs=0 -bar PlugDiff call s:diff() - command! -nargs=? -bar PlugSnapshot call s:snapshot() + command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(0, ) endfunction function! s:to_a(v) @@ -134,21 +204,54 @@ function! s:to_s(v) return type(a:v) == s:TYPE.string ? a:v : join(a:v, "\n") . "\n" endfunction +function! s:glob(from, pattern) + return s:lines(globpath(a:from, a:pattern)) +endfunction + function! s:source(from, ...) + let found = 0 for pattern in a:000 - for vim in s:lines(globpath(a:from, pattern)) + for vim in s:glob(a:from, pattern) execute 'source' s:esc(vim) + let found = 1 endfor endfor + return found endfunction function! s:assoc(dict, key, val) let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) endfunction +function! s:ask(message, ...) + call inputsave() + echohl WarningMsg + let answer = input(a:message.(a:0 ? ' (y/N/a) ' : ' (y/N) ')) + echohl None + call inputrestore() + echo "\r" + return (a:0 && answer =~? '^a') ? 2 : (answer =~? '^y') ? 1 : 0 +endfunction + +function! s:ask_no_interrupt(...) + try + return call('s:ask', a:000) + catch + return 0 + endtry +endfunction + +function! s:lazy(plug, opt) + return has_key(a:plug, a:opt) && + \ (empty(s:to_a(a:plug[a:opt])) || + \ !isdirectory(a:plug.dir) || + \ len(s:glob(s:rtp(a:plug), 'plugin')) || + \ len(s:glob(s:rtp(a:plug), 'after/plugin'))) +endfunction + function! plug#end() if !exists('g:plugs') - return s:err('Call plug#begin() first') + return s:err('plug#end() called without calling plug#begin() first') endif if exists('#PlugLOD') @@ -159,10 +262,15 @@ function! plug#end() endif let lod = { 'ft': {}, 'map': {}, 'cmd': {} } - filetype off + if exists('g:did_load_filetypes') + filetype off + endif for name in g:plugs_order + if !has_key(g:plugs, name) + continue + endif let plug = g:plugs[name] - if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for') + if get(s:loaded, name, 0) || !s:lazy(plug, 'on') && !s:lazy(plug, 'for') let s:loaded[name] = 1 continue endif @@ -176,6 +284,7 @@ function! plug#end() endif call add(s:triggers[name].map, cmd) elseif cmd =~# '^[A-Z]' + let cmd = substitute(cmd, '!*$', '', '') if exists(':'.cmd) != 2 call s:assoc(lod.cmd, cmd, name) endif @@ -190,7 +299,9 @@ function! plug#end() if has_key(plug, 'for') let types = s:to_a(plug.for) if !empty(types) + augroup filetypedetect call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') + augroup END endif for type in types call s:assoc(lod.ft, type, name) @@ -200,7 +311,7 @@ function! plug#end() for [cmd, names] in items(lod.cmd) execute printf( - \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "", , , , %s)', + \ 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "", , , , %s)', \ cmd, string(cmd), string(names)) endfor @@ -208,8 +319,8 @@ function! plug#end() for [mode, map_prefix, key_prefix] in \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] execute printf( - \ '%snoremap %s %s:call lod_map(%s, %s, "%s")', - \ mode, map, map_prefix, string(map), string(names), key_prefix) + \ '%snoremap %s %s:call lod_map(%s, %s, %s, "%s")', + \ mode, map, map_prefix, string(map), string(names), mode != 'i', key_prefix) endfor endfor @@ -223,9 +334,11 @@ function! plug#end() call s:reorg_rtp() filetype plugin indent on if has('vim_starting') - syntax enable + if has('syntax') && !exists('g:syntax_on') + syntax enable + end else - call s:reload() + call s:reload_plugins() endif endfunction @@ -233,9 +346,13 @@ function! s:loaded_names() return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)') endfunction -function! s:reload() +function! s:load_plugin(spec) + call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim') +endfunction + +function! s:reload_plugins() for name in s:loaded_names() - call s:source(s:rtp(g:plugs[name]), 'plugin/**/*.vim', 'after/plugin/**/*.vim') + call s:load_plugin(g:plugs[name]) endfor endfunction @@ -254,8 +371,9 @@ function! s:version_requirement(val, min) endfunction function! s:git_version_requirement(...) - let s:git_version = get(s:, 'git_version', - \ map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)')) + if !exists('s:git_version') + let s:git_version = map(split(split(s:system(['git', '--version']))[2], '\.'), 'str2nr(v:val)') + endif return s:version_requirement(s:git_version, a:000) endfunction @@ -264,11 +382,11 @@ function! s:progress_opt(base) \ s:git_version_requirement(1, 7, 1) ? '--progress' : '' endfunction -if s:is_win - function! s:rtp(spec) - return s:path(a:spec.dir . get(a:spec, 'rtp', '')) - endfunction +function! s:rtp(spec) + return s:path(a:spec.dir . get(a:spec, 'rtp', '')) +endfunction +if s:is_win function! s:path(path) return s:trim(substitute(a:path, '/', '\', 'g')) endfunction @@ -280,11 +398,33 @@ if s:is_win function! s:is_local_plug(repo) return a:repo =~? '^[a-z]:\|^[%~]' endfunction -else - function! s:rtp(spec) - return s:dirpath(a:spec.dir . get(a:spec, 'rtp', '')) + + " Copied from fzf + function! s:wrap_cmds(cmds) + let cmds = [ + \ '@echo off', + \ 'setlocal enabledelayedexpansion'] + \ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) + \ + ['endlocal'] + if has('iconv') + if !exists('s:codepage') + let s:codepage = libcallnr('kernel32.dll', 'GetACP', 0) + endif + return map(cmds, printf('iconv(v:val."\r", "%s", "cp%d")', &encoding, s:codepage)) + endif + return map(cmds, 'v:val."\r"') endfunction + function! s:batchfile(cmd) + let batchfile = s:plug_tempname().'.bat' + call writefile(s:wrap_cmds(a:cmd), batchfile) + let cmd = plug#shellescape(batchfile, {'shell': &shell, 'script': 0}) + if &shell =~# 'powershell\(\.exe\)\?$' + let cmd = '& ' . cmd + endif + return [batchfile, cmd] + endfunction +else function! s:path(path) return s:trim(a:path) endfunction @@ -302,7 +442,12 @@ function! s:err(msg) echohl ErrorMsg echom '[vim-plug] '.a:msg echohl None - return 0 +endfunction + +function! s:warn(cmd, msg) + echohl WarningMsg + execute a:cmd 'a:msg' + echohl None endfunction function! s:esc(path) @@ -338,7 +483,7 @@ function! s:reorg_rtp() let s:middle = get(s:, 'middle', &rtp) let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])') - let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), 'isdirectory(v:val)') + let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), '!empty(v:val)') let rtp = join(map(rtps, 'escape(v:val, ",")'), ',') \ . ','.s:middle.',' \ . join(map(afters, 'escape(v:val, ",")'), ',') @@ -351,6 +496,26 @@ function! s:reorg_rtp() endif endfunction +function! s:doautocmd(...) + if exists('#'.join(a:000, '#')) + execute 'doautocmd' ((v:version > 703 || has('patch442')) ? '' : '') join(a:000) + endif +endfunction + +function! s:dobufread(names) + for name in a:names + let path = s:rtp(g:plugs[name]) + for dir in ['ftdetect', 'ftplugin', 'after/ftdetect', 'after/ftplugin'] + if len(finddir(dir, path)) + if exists('#BufRead') + doautocmd BufRead + endif + return + endif + endfor + endfor +endfunction + function! plug#load(...) if a:0 == 0 return s:err('Argument missing: plugin name(s) required') @@ -358,18 +523,21 @@ function! plug#load(...) if !exists('g:plugs') return s:err('plug#begin was not called') endif - let unknowns = filter(copy(a:000), '!has_key(g:plugs, v:val)') + let names = a:0 == 1 && type(a:1) == s:TYPE.list ? a:1 : a:000 + let unknowns = filter(copy(names), '!has_key(g:plugs, v:val)') if !empty(unknowns) let s = len(unknowns) > 1 ? 's' : '' return s:err(printf('Unknown plugin%s: %s', s, join(unknowns, ', '))) end - for name in a:000 - call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) - endfor - if exists('#BufRead') - doautocmd BufRead - endif - return 1 + let unloaded = filter(copy(names), '!get(s:loaded, v:val, 0)') + if !empty(unloaded) + for name in unloaded + call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) + endfor + call s:dobufread(unloaded) + return 1 + end + return 0 endfunction function! s:remove_triggers(name) @@ -386,7 +554,7 @@ function! s:remove_triggers(name) call remove(s:triggers, a:name) endfunction -function! s:lod(names, types) +function! s:lod(names, types, ...) for name in a:names call s:remove_triggers(name) let s:loaded[name] = 1 @@ -398,30 +566,33 @@ function! s:lod(names, types) for dir in a:types call s:source(rtp, dir.'/**/*.vim') endfor - if exists('#User#'.name) - execute 'doautocmd User' name + if a:0 + if !s:source(rtp, a:1) && !empty(s:glob(rtp, a:2)) + execute 'runtime' a:1 + endif + call s:source(rtp, a:2) endif + call s:doautocmd('User', name) endfor endfunction function! s:lod_ft(pat, names) - call s:lod(a:names, ['plugin', 'after/plugin', 'syntax', 'after/syntax']) + let syn = 'syntax/'.a:pat.'.vim' + call s:lod(a:names, ['plugin', 'after/plugin'], syn, 'after/'.syn) execute 'autocmd! PlugLOD FileType' a:pat - if exists('#filetypeplugin#FileType') - doautocmd filetypeplugin FileType - endif - if exists('#filetypeindent#FileType') - doautocmd filetypeindent FileType - endif + call s:doautocmd('filetypeplugin', 'FileType') + call s:doautocmd('filetypeindent', 'FileType') endfunction function! s:lod_cmd(cmd, bang, l1, l2, args, names) call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) + call s:dobufread(a:names) execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args) endfunction -function! s:lod_map(map, names, prefix) +function! s:lod_map(map, names, with_prefix, prefix) call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) + call s:dobufread(a:names) let extra = '' while 1 let c = getchar(0) @@ -430,38 +601,72 @@ function! s:lod_map(map, names, prefix) endif let extra .= nr2char(c) endwhile - call feedkeys(a:prefix . substitute(a:map, '^', "\", '') . extra) + + if a:with_prefix + let prefix = v:count ? v:count : '' + let prefix .= '"'.v:register.a:prefix + if mode(1) == 'no' + if v:operator == 'c' + let prefix = "\" . prefix + endif + let prefix .= v:operator + endif + call feedkeys(prefix, 'n') + endif + call feedkeys(substitute(a:map, '^', "\", '') . extra) endfunction -function! s:add(repo, ...) +function! plug#(repo, ...) if a:0 > 1 return s:err('Invalid number of arguments (1..2)') endif try let repo = s:trim(a:repo) - let name = fnamemodify(repo, ':t:s?\.git$??') - let spec = extend(s:infer_properties(name, repo), - \ a:0 == 1 ? s:parse_options(a:1) : s:base_spec) + let opts = a:0 == 1 ? s:parse_options(a:1) : s:base_spec + let name = get(opts, 'as', s:plug_fnamemodify(repo, ':t:s?\.git$??')) + let spec = extend(s:infer_properties(name, repo), opts) if !has_key(g:plugs, name) call add(g:plugs_order, name) endif let g:plugs[name] = spec let s:loaded[name] = get(s:loaded, name, 0) catch - return s:err(v:exception) + return s:err(repo . ' ' . v:exception) endtry endfunction function! s:parse_options(arg) let opts = copy(s:base_spec) let type = type(a:arg) + let opt_errfmt = 'Invalid argument for "%s" option of :Plug (expected: %s)' if type == s:TYPE.string + if empty(a:arg) + throw printf(opt_errfmt, 'tag', 'string') + endif let opts.tag = a:arg elseif type == s:TYPE.dict call extend(opts, a:arg) + for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as'] + if has_key(opts, opt) + \ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt])) + throw printf(opt_errfmt, opt, 'string') + endif + endfor + for opt in ['on', 'for'] + if has_key(opts, opt) + \ && type(opts[opt]) != s:TYPE.list + \ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt])) + throw printf(opt_errfmt, opt, 'string or list') + endif + endfor + if has_key(opts, 'do') + \ && type(opts.do) != s:TYPE.funcref + \ && (type(opts.do) != s:TYPE.string || empty(opts.do)) + throw printf(opt_errfmt, 'do', 'string or funcref') + endif if has_key(opts, 'dir') - let opts.dir = s:dirpath(expand(opts.dir)) + let opts.dir = s:dirpath(s:plug_expand(opts.dir)) endif else throw 'Invalid argument type (expected: string or dictionary)' @@ -472,19 +677,18 @@ endfunction function! s:infer_properties(name, repo) let repo = a:repo if s:is_local_plug(repo) - return { 'dir': s:dirpath(expand(repo)) } + return { 'dir': s:dirpath(s:plug_expand(repo)) } else if repo =~ ':' let uri = repo else if repo !~ '/' - let repo = 'vim-scripts/'. repo + throw printf('Invalid argument: %s (implicit `vim-scripts'' expansion is deprecated)', repo) endif let fmt = get(g:, 'plug_url_format', 'https://git::@github.com/%s.git') let uri = printf(fmt, repo) endif - let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') ) - return { 'dir': dir, 'uri': uri } + return { 'dir': s:dirpath(g:plug_home.'/'.a:name), 'uri': uri } endif endfunction @@ -501,7 +705,7 @@ function! plug#helptags() return s:err('plug#begin was not called') endif for spec in values(g:plugs) - let docd = join([spec.dir, 'doc'], '/') + let docd = join([s:rtp(spec), 'doc'], '/') if isdirectory(docd) silent! execute 'helptags' s:esc(docd) endif @@ -521,16 +725,23 @@ function! s:syntax() syn match plugStar /^*/ syn match plugMessage /\(^- \)\@<=.*/ syn match plugName /\(^- \)\@<=[^ ]*:/ + syn match plugSha /\%(: \)\@<=[0-9a-f]\{4,}$/ + syn match plugTag /(tag: [^)]\+)/ syn match plugInstall /\(^+ \)\@<=[^:]*/ syn match plugUpdate /\(^* \)\@<=[^:]*/ - syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha - syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained + syn match plugCommit /^ \X*[0-9a-f]\{7,9} .*/ contains=plugRelDate,plugEdge,plugTag + syn match plugEdge /^ \X\+$/ + syn match plugEdge /^ \X*/ contained nextgroup=plugSha + syn match plugSha /[0-9a-f]\{7,9}/ contained syn match plugRelDate /([^)]*)$/ contained syn match plugNotLoaded /(not loaded)$/ syn match plugError /^x.*/ + syn region plugDeleted start=/^\~ .*/ end=/^\ze\S/ + syn match plugH2 /^.*:\n-\+$/ syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean hi def link plug1 Title hi def link plug2 Repeat + hi def link plugH2 Type hi def link plugX Exception hi def link plugBracket Structure hi def link plugNumber Number @@ -545,8 +756,11 @@ function! s:syntax() hi def link plugUpdate Type hi def link plugError Error + hi def link plugDeleted Ignore hi def link plugRelDate Comment + hi def link plugEdge PreProc hi def link plugSha Identifier + hi def link plugTag Constant hi def link plugNotLoaded Comment endfunction @@ -605,32 +819,57 @@ function! s:switch_out(...) endif endfunction -function! s:prepare() +function! s:finish_bindings() + nnoremap R :call retry() + nnoremap D :PlugDiff + nnoremap S :PlugStatus + nnoremap U :call status_update() + xnoremap U :call status_update() + nnoremap ]] :silent! call section('') + nnoremap [[ :silent! call section('b') +endfunction + +function! s:prepare(...) + if empty(s:plug_getcwd()) + throw 'Invalid current working directory. Cannot proceed.' + endif + + for evar in ['$GIT_DIR', '$GIT_WORK_TREE'] + if exists(evar) + throw evar.' detected. Cannot proceed.' + endif + endfor + call s:job_abort() if s:switch_in() - silent %d _ + if b:plug_preview == 1 + pc + endif + enew else call s:new_window() - nnoremap q :if b:plug_preview==1pcendifbd - nnoremap R :silent! call retry() - nnoremap D :PlugDiff - nnoremap S :PlugStatus - nnoremap U :call status_update() - xnoremap U :call status_update() - nnoremap ]] :silent! call section('') - nnoremap [[ :silent! call section('b') - let b:plug_preview = -1 - let s:plug_tab = tabpagenr() - let s:plug_buf = winbufnr(0) - call s:assign_name() endif - silent! unmap - silent! unmap L - silent! unmap o - silent! unmap X - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable + + nnoremap q :if b:plug_preview==1pcendifbd + if a:0 == 0 + call s:finish_bindings() + endif + let b:plug_preview = -1 + let s:plug_tab = tabpagenr() + let s:plug_buf = winbufnr(0) + call s:assign_name() + + for k in ['', 'L', 'o', 'X', 'd', 'dd'] + execute 'silent! unmap ' k + endfor + setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline modifiable nospell + if exists('+colorcolumn') + setlocal colorcolumn= + endif setf vim-plug - call s:syntax() + if exists('g:syntax_on') + call s:syntax() + endif endfunction function! s:assign_name() @@ -645,6 +884,52 @@ function! s:assign_name() silent! execute 'f' fnameescape(name) endfunction +function! s:chsh(swap) + let prev = [&shell, &shellcmdflag, &shellredir] + if !s:is_win + set shell=sh + endif + if a:swap + if &shell =~# 'powershell\(\.exe\)\?$' || &shell =~# 'pwsh$' + let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s' + elseif &shell =~# 'sh' || &shell =~# 'cmd\(\.exe\)\?$' + set shellredir=>%s\ 2>&1 + endif + endif + return prev +endfunction + +function! s:bang(cmd, ...) + let batchfile = '' + try + let [sh, shellcmdflag, shrd] = s:chsh(a:0) + " FIXME: Escaping is incomplete. We could use shellescape with eval, + " but it won't work on Windows. + let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd + if s:is_win + let [batchfile, cmd] = s:batchfile(cmd) + endif + let g:_plug_bang = (s:is_win && has('gui_running') ? 'silent ' : '').'!'.escape(cmd, '#!%') + execute "normal! :execute g:_plug_bang\\" + finally + unlet g:_plug_bang + let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd] + if s:is_win && filereadable(batchfile) + call delete(batchfile) + endif + endtry + return v:shell_error ? 'Exit status: ' . v:shell_error : '' +endfunction + +function! s:regress_bar() + let bar = substitute(getline(2)[1:-2], '.*\zs=', 'x', '') + call s:progress_bar(2, bar, len(bar)) +endfunction + +function! s:is_updated(dir) + return !empty(s:system_chomp(['git', 'log', '--pretty=format:%h', 'HEAD...HEAD@{1}'], a:dir)) +endfunction + function! s:do(pull, force, todo) for [name, spec] in items(a:todo) if !isdirectory(spec.dir) @@ -652,26 +937,34 @@ function! s:do(pull, force, todo) endif let installed = has_key(s:update.new, name) let updated = installed ? 0 : - \ (a:pull && index(s:update.errors, name) < 0 && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir))) + \ (a:pull && index(s:update.errors, name) < 0 && s:is_updated(spec.dir)) if a:force || installed || updated execute 'cd' s:esc(spec.dir) call append(3, '- Post-update hook for '. name .' ... ') let error = '' let type = type(spec.do) if type == s:TYPE.string - try - " FIXME: Escaping is incomplete. We could use shellescape with eval, - " but it won't work on Windows. - let g:_plug_do = '!'.escape(spec.do, '#!%') - execute "normal! :execute g:_plug_do\\" - finally - if v:shell_error - let error = 'Exit status: ' . v:shell_error + if spec.do[0] == ':' + if !get(s:loaded, name, 0) + let s:loaded[name] = 1 + call s:reorg_rtp() endif - unlet g:_plug_do - endtry + call s:load_plugin(spec) + try + execute spec.do[1:] + catch + let error = v:exception + endtry + if !s:plug_window_exists() + cd - + throw 'Warning: vim-plug was terminated by the post-update hook of '.name + endif + else + let error = s:bang(spec.do) + endif elseif type == s:TYPE.funcref try + call s:load_plugin(spec) let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') call spec.do({ 'name': name, 'status': status, 'force': a:force }) catch @@ -680,8 +973,13 @@ function! s:do(pull, force, todo) else let error = 'Invalid hook type' endif + call s:switch_in() call setline(4, empty(error) ? (getline(4) . 'OK') \ : ('x' . getline(4)[1:] . error)) + if !empty(error) + call add(s:update.errors, name) + call s:regress_bar() + endif cd - endif endfor @@ -691,32 +989,14 @@ function! s:hash_match(a, b) return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0 endfunction -function! s:checkout(plugs) - for [name, spec] in items(a:plugs) - let sha = spec.commit - call append(3, '- Checking out '.sha[:6].' of '.name.' ... ') - redraw - - let error = [] - let output = s:lines(s:system('git rev-parse HEAD', spec.dir)) - if v:shell_error - let error = output - elseif !s:hash_match(sha, output[0]) - let output = s:lines(s:system( - \ 'git fetch --depth 999999 && git checkout '.sha, spec.dir)) - if v:shell_error - let error = output - endif - endif - if empty(error) - call setline(4, getline(4) . 'OK') - else - call setline(4, 'x'.getline(4)[1:] . 'Error') - for line in reverse(error) - call append(4, ' '.line) - endfor - endif - endfor +function! s:checkout(spec) + let sha = a:spec.commit + let output = s:system(['git', 'rev-parse', 'HEAD'], a:spec.dir) + if !v:shell_error && !s:hash_match(sha, s:lines(output)[0]) + let output = s:system( + \ 'git fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir) + endif + return output endfunction function! s:finish(pull) @@ -725,7 +1005,7 @@ function! s:finish(pull) let s = new_frozen > 1 ? 's' : '' call append(3, printf('- Installed %d frozen plugin%s', new_frozen, s)) endif - call append(3, '- Finishing ... ') + call append(3, '- Finishing ... ') | 4 redraw call plug#helptags() call plug#end() @@ -736,16 +1016,18 @@ function! s:finish(pull) call add(msgs, "Press 'R' to retry.") endif if a:pull && len(s:update.new) < len(filter(getline(5, '$'), - \ "v:val =~ '^- ' && stridx(v:val, 'Already up-to-date') < 0")) + \ "v:val =~ '^- ' && v:val !~# 'Already up.to.date'")) call add(msgs, "Press 'D' to see the updated changes.") endif echo join(msgs, ' ') + call s:finish_bindings() endfunction function! s:retry() if empty(s:update.errors) return endif + echo call s:update_impl(s:update.pull, s:update.force, \ extend(copy(s:update.errors), [s:update.threads])) endfunction @@ -758,20 +1040,29 @@ function! s:names(...) return sort(filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')) endfunction +function! s:check_ruby() + silent! ruby require 'thread'; VIM::command("let g:plug_ruby = '#{RUBY_VERSION}'") + if !exists('g:plug_ruby') + redraw! + return s:warn('echom', 'Warning: Ruby interface is broken') + endif + let ruby_version = split(g:plug_ruby, '\.') + unlet g:plug_ruby + return s:version_requirement(ruby_version, [1, 8, 7]) +endfunction + function! s:update_impl(pull, force, args) abort - let args = copy(a:args) + let sync = index(a:args, '--sync') >= 0 || has('vim_starting') + let args = filter(copy(a:args), 'v:val != "--sync"') let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? - \ remove(args, -1) : get(g:, 'plug_threads', s:is_win ? 1 : 16) + \ remove(args, -1) : get(g:, 'plug_threads', 16) let managed = filter(copy(g:plugs), 's:is_managed(v:key)') let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : \ filter(managed, 'index(args, v:key) >= 0') if empty(todo) - echohl WarningMsg - echo 'No plugin to '. (a:pull ? 'update' : 'install') . '.' - echohl None - return + return s:warn('echo', 'No plugin to '. (a:pull ? 'update' : 'install')) endif if !s:is_win && s:git_version_requirement(2, 3) @@ -793,14 +1084,12 @@ function! s:update_impl(pull, force, args) abort endif if has('nvim') && !exists('*jobwait') && threads > 1 - echohl WarningMsg - echomsg 'vim-plug: update Neovim for parallel installer' - echohl None + call s:warn('echom', '[vim-plug] Update Neovim for parallel installer') endif - let python = (has('python') || has('python3')) && !s:is_win && !has('win32unix') - \ && (!s:nvim || has('vim_starting')) - let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) + let use_job = s:nvim || s:vim8 + let python = (has('python') || has('python3')) && !use_job + let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && threads > 1 && s:check_ruby() let s:update = { \ 'start': reltime(), @@ -810,23 +1099,34 @@ function! s:update_impl(pull, force, args) abort \ 'pull': a:pull, \ 'force': a:force, \ 'new': {}, - \ 'threads': (python || ruby || s:nvim) ? min([len(todo), threads]) : 1, + \ 'threads': (python || ruby || use_job) ? min([len(todo), threads]) : 1, \ 'bar': '', \ 'fin': 0 \ } - call s:prepare() + call s:prepare(1) call append(0, ['', '']) normal! 2G silent! redraw - let s:clone_opt = get(g:, 'plug_shallow', 1) ? - \ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : '' + let s:clone_opt = [] + if get(g:, 'plug_shallow', 1) + call extend(s:clone_opt, ['--depth', '1']) + if s:git_version_requirement(1, 7, 10) + call add(s:clone_opt, '--no-single-branch') + endif + endif + + if has('win32unix') || has('wsl') + call extend(s:clone_opt, ['-c', 'core.eol=lf', '-c', 'core.autocrlf=input']) + endif + + let s:submodule_opt = s:git_version_requirement(2, 8) ? ' --jobs='.threads : '' " Python version requirement (>= 2.7) - if python && !has('python3') && !ruby && !s:nvim && s:update.threads > 1 + if python && !has('python3') && !ruby && !use_job && s:update.threads > 1 redir => pyv - silent python import platform; print(platform.python_version()) + silent python import platform; print platform.python_version() redir END let python = s:version_requirement( \ map(split(split(pyv)[0], '\.'), 'str2nr(v:val)'), [2, 6]) @@ -865,16 +1165,76 @@ function! s:update_impl(pull, force, args) abort endtry else call s:update_vim() + while use_job && sync + sleep 100m + if s:update.fin + break + endif + endwhile endif endfunction +function! s:log4(name, msg) + call setline(4, printf('- %s (%s)', a:msg, a:name)) + redraw +endfunction + function! s:update_finish() if exists('s:git_terminal_prompt') let $GIT_TERMINAL_PROMPT = s:git_terminal_prompt endif if s:switch_in() - call s:checkout(filter(copy(s:update.all), 'has_key(v:val, "commit")')) - call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'has_key(v:val, "do")')) + call append(3, '- Updating ...') | 4 + for [name, spec] in items(filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && (s:update.force || s:update.pull || has_key(s:update.new, v:key))')) + let [pos, _] = s:logpos(name) + if !pos + continue + endif + if has_key(spec, 'commit') + call s:log4(name, 'Checking out '.spec.commit) + let out = s:checkout(spec) + elseif has_key(spec, 'tag') + let tag = spec.tag + if tag =~ '\*' + let tags = s:lines(s:system('git tag --list '.plug#shellescape(tag).' --sort -version:refname 2>&1', spec.dir)) + if !v:shell_error && !empty(tags) + let tag = tags[0] + call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag)) + call append(3, '') + endif + endif + call s:log4(name, 'Checking out '.tag) + let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir) + else + let branch = get(spec, 'branch', 'master') + 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 + if !v:shell_error && filereadable(spec.dir.'/.gitmodules') && + \ (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.') + let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir) + endif + let msg = s:format_message(v:shell_error ? 'x': '-', name, out) + if v:shell_error + call add(s:update.errors, name) + call s:regress_bar() + silent execute pos 'd _' + call append(4, msg) | 4 + elseif !empty(out) + call setline(pos, msg[0]) + endif + redraw + endfor + silent 4 d _ + try + call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")')) + catch + call s:warn('echom', v:exception) + call s:warn('echo', '') + return + endtry call s:finish(s:update.pull) call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') call s:switch_out('normal! gg') @@ -882,66 +1242,114 @@ function! s:update_finish() endfunction function! s:job_abort() - if !s:nvim || !exists('s:jobs') + if (!s:nvim && !s:vim8) || !exists('s:jobs') return endif for [name, j] in items(s:jobs) - silent! call jobstop(j.jobid) + if s:nvim + silent! call jobstop(j.jobid) + elseif s:vim8 + silent! call job_stop(j.jobid) + endif if j.new - call s:system('rm -rf ' . s:shellesc(g:plugs[name].dir)) + call s:rm_rf(g:plugs[name].dir) endif endfor let s:jobs = {} endfunction -" When a:event == 'stdout', data = list of strings -" When a:event == 'exit', data = returncode -function! s:job_handler(job_id, data, event) abort - if !s:plug_window_exists() " plug window closed - return s:job_abort() - endif +function! s:last_non_empty_line(lines) + let len = len(a:lines) + for idx in range(len) + let line = a:lines[len-idx-1] + if !empty(line) + return line + endif + endfor + return '' +endfunction - if a:event == 'stdout' - let self.result .= substitute(s:to_s(a:data), '[\r\n]', '', 'g') . "\n" - " To reduce the number of buffer updates - let self.tick = get(self, 'tick', -1) + 1 - if self.tick % len(s:jobs) == 0 - call s:log(self.new ? '+' : '*', self.name, self.result) - endif - elseif a:event == 'exit' - let self.running = 0 - if a:data != 0 - let self.error = 1 - endif - call s:reap(self.name) - call s:tick() +function! s:job_out_cb(self, data) abort + let self = a:self + let data = remove(self.lines, -1) . a:data + let lines = map(split(data, "\n", 1), 'split(v:val, "\r", 1)[-1]') + call extend(self.lines, lines) + " To reduce the number of buffer updates + let self.tick = get(self, 'tick', -1) + 1 + if !self.running || self.tick % len(s:jobs) == 0 + let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-') + let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines) + call s:log(bullet, self.name, result) endif endfunction +function! s:job_exit_cb(self, data) abort + let a:self.running = 0 + let a:self.error = a:data != 0 + call s:reap(a:self.name) + call s:tick() +endfunction + +function! s:job_cb(fn, job, ch, data) + if !s:plug_window_exists() " plug window closed + return s:job_abort() + endif + call call(a:fn, [a:job, a:data]) +endfunction + +function! s:nvim_cb(job_id, data, event) dict abort + return (a:event == 'stdout' || a:event == 'stderr') ? + \ s:job_cb('s:job_out_cb', self, 0, join(a:data, "\n")) : + \ s:job_cb('s:job_exit_cb', self, 0, a:data) +endfunction + function! s:spawn(name, cmd, opts) - let job = { 'name': a:name, 'running': 1, 'error': 0, 'result': '', - \ 'new': get(a:opts, 'new', 0), - \ 'on_stdout': function('s:job_handler'), - \ 'on_exit' : function('s:job_handler'), - \ } + let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [''], + \ 'new': get(a:opts, 'new', 0) } let s:jobs[a:name] = job if s:nvim - let argv = [ 'sh', '-c', - \ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd) ] - let jid = jobstart(argv, job) + if has_key(a:opts, 'dir') + let job.cwd = a:opts.dir + endif + let argv = a:cmd + call extend(job, { + \ 'on_stdout': function('s:nvim_cb'), + \ 'on_stderr': function('s:nvim_cb'), + \ 'on_exit': function('s:nvim_cb'), + \ }) + let jid = s:plug_call('jobstart', argv, job) if jid > 0 let job.jobid = jid else let job.running = 0 let job.error = 1 - let job.result = jid < 0 ? 'sh is not executable' : - \ 'Invalid arguments (or job table is full)' + let job.lines = [jid < 0 ? argv[0].' is not executable' : + \ 'Invalid arguments (or job table is full)'] + endif + elseif s:vim8 + let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"script": 0})')) + if has_key(a:opts, 'dir') + let cmd = s:with_cd(cmd, a:opts.dir, 0) + endif + let argv = s:is_win ? ['cmd', '/s', '/c', '"'.cmd.'"'] : ['sh', '-c', cmd] + let jid = job_start(s:is_win ? join(argv, ' ') : argv, { + \ 'out_cb': function('s:job_cb', ['s:job_out_cb', job]), + \ 'err_cb': function('s:job_cb', ['s:job_out_cb', job]), + \ 'exit_cb': function('s:job_cb', ['s:job_exit_cb', job]), + \ 'err_mode': 'raw', + \ 'out_mode': 'raw' + \}) + if job_status(jid) == 'run' + let job.jobid = jid + else + let job.running = 0 + let job.error = 1 + let job.lines = ['Failed to start job'] endif else - let params = has_key(a:opts, 'dir') ? [a:cmd, a:opts.dir] : [a:cmd] - let job.result = call('s:system', params) + let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [a:cmd, a:opts.dir] : [a:cmd])) let job.error = v:shell_error != 0 let job.running = 0 endif @@ -956,7 +1364,9 @@ function! s:reap(name) endif let s:update.bar .= job.error ? 'x' : '=' - call s:log(job.error ? 'x' : '-', a:name, job.result) + let bullet = job.error ? 'x' : '-' + 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) call s:bar() call remove(s:jobs, a:name) @@ -973,26 +1383,34 @@ function! s:bar() endfunction function! s:logpos(name) - for i in range(1, line('$')) + let max = line('$') + for i in range(4, max > 4 ? max : 4) if getline(i) =~# '^[-+x*] '.a:name.':' - return i + for j in range(i + 1, max > 5 ? max : 5) + if getline(j) !~ '^ ' + return [i, j - 1] + endif + endfor + return [i, i] endif endfor - return 0 + return [0, 0] endfunction function! s:log(bullet, name, lines) if s:switch_in() - let pos = s:logpos(a:name) - if pos > 0 - execute pos 'd _' - if pos > winheight('.') - let pos = 4 + let [b, e] = s:logpos(a:name) + if b > 0 + silent execute printf('%d,%d d _', b, e) + if b > winheight('.') + let b = 4 endif else - let pos = 4 + let b = 4 endif - call append(pos - 1, s:format_message(a:bullet, a:name, a:lines)) + " FIXME For some reason, nomodifiable is set after :d in vim8 + setlocal modifiable + call append(b - 1, s:format_message(a:bullet, a:name, a:lines)) call s:switch_out() endif endfunction @@ -1006,49 +1424,51 @@ endfunction function! s:tick() let pull = s:update.pull - let prog = s:progress_opt(s:nvim) + let prog = s:progress_opt(s:nvim || s:vim8) while 1 " Without TCO, Vim stack is bound to explode if empty(s:update.todo) if empty(s:jobs) && !s:update.fin - let s:update.fin = 1 call s:update_finish() + let s:update.fin = 1 endif return endif let name = keys(s:update.todo)[0] let spec = remove(s:update.todo, name) - let new = !isdirectory(spec.dir) + let new = empty(globpath(spec.dir, '.git', 1)) call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') redraw let has_tag = has_key(spec, 'tag') - let checkout = s:shellesc(has_tag ? spec.tag : spec.branch) - let merge = s:shellesc(has_tag ? spec.tag : 'origin/'.spec.branch) - if !new - let error = s:git_validate(spec, 0) + let [error, _] = s:git_validate(spec, 0) if empty(error) if pull - let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : '' - call s:spawn(name, - \ printf('(git fetch %s %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only %s 2>&1 && git submodule update --init --recursive 2>&1)', - \ fetch_opt, prog, checkout, merge), { 'dir': spec.dir }) + let cmd = ['git', 'fetch'] + if has_tag && !empty(globpath(spec.dir, '.git/shallow')) + call extend(cmd, ['--depth', '99999999']) + endif + if !empty(prog) + call add(cmd, prog) + endif + call s:spawn(name, cmd, { 'dir': spec.dir }) else - let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 } + let s:jobs[name] = { 'running': 0, 'lines': ['Already installed'], 'error': 0 } endif else - let s:jobs[name] = { 'running': 0, 'result': error, 'error': 1 } + let s:jobs[name] = { 'running': 0, 'lines': s:lines(error), 'error': 1 } endif else - call s:spawn(name, - \ printf('git clone %s %s --recursive %s -b %s %s 2>&1', - \ has_tag ? '' : s:clone_opt, - \ prog, - \ s:shellesc(spec.uri), - \ checkout, - \ s:shellesc(s:trim(spec.dir))), { 'new': 1 }) + let cmd = ['git', 'clone'] + if !has_tag + call extend(cmd, s:clone_opt) + endif + if !empty(prog) + call add(cmd, prog) + endif + call s:spawn(name, extend(cmd, [spec.uri, s:trim(spec.dir)]), { 'new': 1 }) endif if !s:jobs[name].running @@ -1063,7 +1483,6 @@ endfunction function! s:update_python() let py_exe = has('python') ? 'python' : 'python3' execute py_exe "<< EOF" -""" Due to use of signals this function is POSIX only. """ import datetime import functools import os @@ -1086,13 +1505,15 @@ G_NVIM = vim.eval("has('nvim')") == '1' G_PULL = vim.eval('s:update.pull') == '1' G_RETRIES = int(vim.eval('get(g:, "plug_retries", 2)')) + 1 G_TIMEOUT = int(vim.eval('get(g:, "plug_timeout", 60)')) -G_CLONE_OPT = vim.eval('s:clone_opt') +G_CLONE_OPT = ' '.join(vim.eval('s:clone_opt')) G_PROGRESS = vim.eval('s:progress_opt(1)') G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads')) G_STOP = thr.Event() +G_IS_WIN = vim.eval('s:is_win') == '1' class PlugError(Exception): - pass + def __init__(self, msg): + self.msg = msg class CmdTimedOut(PlugError): pass class CmdFailed(PlugError): @@ -1103,10 +1524,9 @@ class Action(object): INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] class Buffer(object): - def __init__(self, lock, num_plugs, is_pull, is_win): + def __init__(self, lock, num_plugs, is_pull): self.bar = '' self.event = 'Updating' if is_pull else 'Installing' - self.is_win = is_win self.lock = lock self.maxy = int(vim.eval('winheight(".")')) self.num_plugs = num_plugs @@ -1134,8 +1554,7 @@ class Buffer(object): with self.lock: vim.command('normal! 2G') - if not self.is_win: - vim.command('redraw') + vim.command('redraw') def write(self, action, name, lines): first, rest = lines[0], lines[1:] @@ -1164,9 +1583,12 @@ class Buffer(object): pass class Command(object): + CD = 'cd /d' if G_IS_WIN else 'cd' + def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): self.cmd = cmd - self.cmd_dir = cmd_dir + if cmd_dir: + self.cmd = '{0} {1} && {2}'.format(Command.CD, cmd_dir, self.cmd) self.timeout = timeout self.callback = cb if cb else (lambda msg: None) self.clean = clean if clean else (lambda: None) @@ -1216,9 +1638,11 @@ class Command(object): try: tfile = tempfile.NamedTemporaryFile(mode='w+b') - self.proc = subprocess.Popen(self.cmd, cwd=self.cmd_dir, stdout=tfile, - stderr=subprocess.STDOUT, shell=True, - preexec_fn=os.setsid) + preexec_fn = not G_IS_WIN and os.setsid or None + self.proc = subprocess.Popen(self.cmd, stdout=tfile, + stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, shell=True, + preexec_fn=preexec_fn) thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,)) thrd.start() @@ -1236,7 +1660,7 @@ class Command(object): if first_line or random.random() < G_LOG_PROB: first_line = False - line = nonblock_read(tfile.name) + line = '' if G_IS_WIN else nonblock_read(tfile.name) if line: self.callback([line]) @@ -1260,7 +1684,10 @@ class Command(object): def terminate(self): """ Terminate process and cleanup. """ if self.alive: - os.killpg(self.proc.pid, signal.SIGTERM) + if G_IS_WIN: + os.kill(self.proc.pid, signal.SIGINT) + else: + os.killpg(self.proc.pid, signal.SIGTERM) self.clean() class Plugin(object): @@ -1269,10 +1696,7 @@ class Plugin(object): self.args = args self.buf_q = buf_q self.lock = lock - tag = args.get('tag', 0) - self.checkout = esc(tag if tag else args['branch']) - self.merge = esc(tag if tag else 'origin/' + args['branch']) - self.tag = tag + self.tag = args.get('tag', 0) def manage(self): try: @@ -1283,7 +1707,7 @@ class Plugin(object): with self.lock: thread_vim_command("let s:update.new['{0}'] = 1".format(self.name)) except PlugError as exc: - self.write(Action.ERROR, self.name, [str(exc)]) + self.write(Action.ERROR, self.name, exc.msg) except KeyboardInterrupt: G_STOP.set() self.write(Action.ERROR, self.name, ['Interrupted!']) @@ -1295,6 +1719,8 @@ class Plugin(object): def install(self): target = self.args['dir'] + if target[-1] == '\\': + target = target[0:-1] def clean(target): def _clean(): @@ -1306,24 +1732,26 @@ class Plugin(object): self.write(Action.INSTALL, self.name, ['Installing ...']) callback = functools.partial(self.write, Action.INSTALL, self.name) - cmd = 'git clone {0} {1} --recursive {2} -b {3} {4} 2>&1'.format( + cmd = 'git clone {0} {1} {2} {3} 2>&1'.format( '' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'], - self.checkout, esc(target)) + esc(target)) com = Command(cmd, None, G_TIMEOUT, callback, clean(target)) result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) def repo_uri(self): - cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url' + cmd = 'git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url' command = Command(cmd, self.args['dir'], G_TIMEOUT,) result = command.execute(G_RETRIES) return result[-1] def update(self): - match = re.compile(r'git::?@') - actual_uri = re.sub(match, '', self.repo_uri()) - expect_uri = re.sub(match, '', self.args['uri']) - if actual_uri != expect_uri: + actual_uri = self.repo_uri() + expect_uri = self.args['uri'] + regex = re.compile(r'^(?:\w+://)?(?:[^@/]*@)?([^:/]*(?::[0-9]*)?)[:/](.*?)(?:\.git)?/?$') + ma = regex.match(actual_uri) + mb = regex.match(expect_uri) + if ma is None or mb is None or ma.groups() != mb.groups(): msg = ['', 'Invalid URI: {0}'.format(actual_uri), 'Expected {0}'.format(expect_uri), @@ -1334,11 +1762,7 @@ class Plugin(object): self.write(Action.UPDATE, self.name, ['Updating ...']) callback = functools.partial(self.write, Action.UPDATE, self.name) fetch_opt = '--depth 99999999' if self.tag and os.path.isfile(os.path.join(self.args['dir'], '.git/shallow')) else '' - cmds = ['git fetch {0} {1}'.format(fetch_opt, G_PROGRESS), - 'git checkout -q {0}'.format(self.checkout), - 'git merge --ff-only {0}'.format(self.merge), - 'git submodule update --init --recursive'] - cmd = ' 2>&1 && '.join(cmds) + cmd = 'git fetch {0} {1} 2>&1'.format(fetch_opt, G_PROGRESS) com = Command(cmd, self.args['dir'], G_TIMEOUT, callback) result = com.execute(G_RETRIES) self.write(Action.DONE, self.name, result[-1:]) @@ -1411,10 +1835,9 @@ def main(): nthreads = int(vim.eval('s:update.threads')) plugs = vim.eval('s:update.todo') mac_gui = vim.eval('s:mac_gui') == '1' - is_win = vim.eval('s:is_win') == '1' lock = thr.Lock() - buf = Buffer(lock, len(plugs), G_PULL, is_win) + buf = Buffer(lock, len(plugs), G_PULL) buf_q, work_q = queue.Queue(), queue.Queue() for work in plugs.items(): work_q.put(work) @@ -1431,7 +1854,7 @@ def main(): while not buf_q.empty() or thr.active_count() != start_cnt: try: action, name, msg = buf_q.get(True, 0.25) - buf.write(action, name, msg) + buf.write(action, name, ['OK'] if not msg else msg) buf_q.task_done() except queue.Empty: pass @@ -1471,16 +1894,25 @@ function! s:update_ruby() def killall pid pids = [pid] - unless `which pgrep 2> /dev/null`.empty? - children = pids - until children.empty? - children = children.map { |pid| - `pgrep -P #{pid}`.lines.map { |l| l.chomp } - }.flatten - pids += children + if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM + pids.each { |pid| Process.kill 'INT', pid.to_i rescue nil } + else + unless `which pgrep 2> /dev/null`.empty? + children = pids + until children.empty? + children = children.map { |pid| + `pgrep -P #{pid}`.lines.map { |l| l.chomp } + }.flatten + pids += children + end end + pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } end - pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } + end + + def compare_git_uri a, b + regex = %r{^(?:\w+://)?(?:[^@/]*@)?([^:/]*(?::[0-9]*)?)[:/](.*?)(?:\.git)?/?$} + regex.match(a).to_a.drop(1) == regex.match(b).to_a.drop(1) end require 'thread' @@ -1495,6 +1927,7 @@ function! s:update_ruby() tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1 nthr = VIM::evaluate('s:update.threads').to_i maxy = VIM::evaluate('winheight(".")').to_i + vim7 = VIM::evaluate('v:version').to_i <= 703 && RUBY_PLATFORM =~ /darwin/ cd = iswin ? 'cd /d' : 'cd' tot = VIM::evaluate('len(s:update.todo)') || 0 bar = '' @@ -1506,7 +1939,7 @@ function! s:update_ruby() $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})" $curbuf[2] = '[' + bar.ljust(tot) + ']' VIM::command('normal! 2G') - VIM::command('redraw') unless iswin + VIM::command('redraw') } where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } } log = proc { |name, result, type| @@ -1521,7 +1954,7 @@ function! s:update_ruby() end result = if type || type.nil? - ["#{b} #{name}: #{result.lines.to_a.last}"] + ["#{b} #{name}: #{result.lines.to_a.last || 'OK'}"] elsif result =~ /^Interrupted|^Timeout/ ["#{b} #{name}: #{result}"] else @@ -1584,12 +2017,17 @@ function! s:update_ruby() main = Thread.current threads = [] watcher = Thread.new { - while VIM::evaluate('getchar(1)') - sleep 0.1 + if vim7 + while VIM::evaluate('getchar(1)') + sleep 0.1 + end + else + require 'io/console' # >= Ruby 1.9 + nil until IO.console.getch == 3.chr end mtx.synchronize do running = false - threads.each { |t| t.raise Interrupt } + threads.each { |t| t.raise Interrupt } unless vim7 end threads.each { |t| t.join rescue nil } main.kill @@ -1604,22 +2042,19 @@ function! s:update_ruby() end } if VIM::evaluate('s:mac_gui') == 1 - clone_opt = VIM::evaluate('s:clone_opt') + clone_opt = VIM::evaluate('s:clone_opt').join(' ') progress = VIM::evaluate('s:progress_opt(1)') nthr.times do mtx.synchronize do threads << Thread.new { while pair = take1.call name = pair.first - dir, uri, branch, tag = pair.last.values_at *%w[dir uri branch tag] - checkout = esc(tag ? tag : branch) - merge = esc(tag ? tag : "origin/#{branch}") - subm = "git submodule update --init --recursive 2>&1" + dir, uri, tag = pair.last.values_at *%w[dir uri tag] exists = File.directory? dir ok, result = if exists - dir = iswin ? dir : esc(dir) - ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil + chdir = "#{cd} #{iswin ? dir : esc(dir)}" + ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url", nil, nil, nil current_uri = data.lines.to_a.last if !ret if data =~ /^Interrupted|^Timeout/ @@ -1627,7 +2062,7 @@ function! s:update_ruby() else [false, [data.chomp, "PlugClean required."].join($/)] end - elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '') + elsif !compare_git_uri(current_uri, uri) [false, ["Invalid URI: #{current_uri}", "Expected: #{uri}", "PlugClean required."].join($/)] @@ -1635,7 +2070,7 @@ function! s:update_ruby() if pull log.call name, 'Updating ...', :update fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : '' - bt.call "#{cd} #{dir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil + bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1", name, :update, nil else [true, skip] end @@ -1643,7 +2078,7 @@ function! s:update_ruby() else d = esc dir.sub(%r{[\\/]+$}, '') log.call name, 'Installing ...', :install - bt.call "git clone #{clone_opt unless tag} #{progress} --recursive #{uri} -b #{checkout} #{d} 2>&1", name, :install, proc { + bt.call "git clone #{clone_opt unless tag} #{progress} #{uri} #{d} 2>&1", name, :install, proc { FileUtils.rm_rf dir } end @@ -1660,12 +2095,49 @@ function! s:update_ruby() EOF endfunction -function! s:shellesc(arg) - return '"'.escape(a:arg, '"').'"' +function! s:shellesc_cmd(arg, script) + let escaped = substitute('"'.a:arg.'"', '[&|<>()@^!"]', '^&', 'g') + return substitute(escaped, '%', (a:script ? '%' : '^') . '&', 'g') +endfunction + +function! s:shellesc_ps1(arg) + return "'".substitute(escape(a:arg, '\"'), "'", "''", 'g')."'" +endfunction + +function! s:shellesc_sh(arg) + return "'".substitute(a:arg, "'", "'\\\\''", 'g')."'" +endfunction + +" Escape the shell argument based on the shell. +" Vim and Neovim's shellescape() are insufficient. +" 1. shellslash determines whether to use single/double quotes. +" Double-quote escaping is fragile for cmd.exe. +" 2. It does not work for powershell. +" 3. It does not work for *sh shells if the command is executed +" via cmd.exe (ie. cmd.exe /c sh -c command command_args) +" 4. It does not support batchfile syntax. +" +" Accepts an optional dictionary with the following keys: +" - shell: same as Vim/Neovim 'shell' option. +" If unset, fallback to 'cmd.exe' on Windows or 'sh'. +" - script: If truthy and shell is cmd.exe, escape for batchfile syntax. +function! plug#shellescape(arg, ...) + if a:arg =~# '^[A-Za-z0-9_/:.-]\+$' + return a:arg + endif + let opts = a:0 > 0 && type(a:1) == s:TYPE.dict ? a:1 : {} + let shell = get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh') + let script = get(opts, 'script', 1) + if shell =~# 'cmd\(\.exe\)\?$' + return s:shellesc_cmd(a:arg, script) + elseif shell =~# 'powershell\(\.exe\)\?$' || shell =~# 'pwsh$' + return s:shellesc_ps1(a:arg) + endif + return s:shellesc_sh(a:arg) endfunction function! s:glob_dir(path) - return map(filter(s:lines(globpath(a:path, '**')), 'isdirectory(v:val)'), 's:dirpath(v:val)') + return map(filter(s:glob(a:path, '**'), 'isdirectory(v:val)'), 's:dirpath(v:val)') endfunction function! s:progress_bar(line, bar, total) @@ -1673,9 +2145,15 @@ function! s:progress_bar(line, bar, total) endfunction function! s:compare_git_uri(a, b) - let a = substitute(a:a, 'git:\{1,2}@', '', '') - let b = substitute(a:b, 'git:\{1,2}@', '', '') - return a ==# b + " See `git help clone' + " https:// [user@] github.com[:port] / junegunn/vim-plug [.git] + " [git@] github.com[:port] : junegunn/vim-plug [.git] + " file:// / junegunn/vim-plug [/] + " / junegunn/vim-plug [/] + let pat = '^\%(\w\+://\)\='.'\%([^@/]*@\)\='.'\([^:/]*\%(:[0-9]*\)\=\)'.'[:/]'.'\(.\{-}\)'.'\%(\.git\)\=/\?$' + let ma = matchlist(a:a, pat) + let mb = matchlist(a:b, pat) + return ma[1:2] ==# mb[1:2] endfunction function! s:format_message(bullet, name, message) @@ -1687,20 +2165,41 @@ function! s:format_message(bullet, name, message) endif endfunction -function! s:with_cd(cmd, dir) - return printf('cd%s %s && %s', s:is_win ? ' /d' : '', s:shellesc(a:dir), a:cmd) +function! s:with_cd(cmd, dir, ...) + 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) endfunction function! s:system(cmd, ...) + let batchfile = '' try - let [sh, shrd] = [&shell, &shellredir] - if !s:is_win - set shell=sh shellredir=>%s\ 2>&1 + let [sh, shellcmdflag, shrd] = s:chsh(1) + if type(a:cmd) == s:TYPE.list + " Neovim's system() supports list argument to bypass the shell + " but it cannot set the working directory for the command. + " Assume that the command does not rely on the shell. + if has('nvim') && a:0 == 0 + return system(a:cmd) + endif + let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})')) + if &shell =~# 'powershell\(\.exe\)\?$' + let cmd = '& ' . cmd + endif + else + let cmd = a:cmd endif - let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd - return system(s:is_win ? '('.cmd.')' : cmd) + if a:0 > 0 + let cmd = s:with_cd(cmd, a:1, type(a:cmd) != s:TYPE.list) + endif + if s:is_win && type(a:cmd) != s:TYPE.list + let [batchfile, cmd] = s:batchfile(cmd) + endif + return system(cmd) finally - let [&shell, &shellredir] = [sh, shrd] + let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd] + if s:is_win && filereadable(batchfile) + call delete(batchfile) + endif endtry endfunction @@ -1712,7 +2211,7 @@ endfunction function! s:git_validate(spec, check_branch) let err = '' if isdirectory(a:spec.dir) - let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url', a:spec.dir)) + let result = s:lines(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config -f .git/config remote.origin.url', a:spec.dir)) let remote = result[-1] if v:shell_error let err = join([remote, 'PlugClean required.'], "\n") @@ -1735,7 +2234,7 @@ function! s:git_validate(spec, check_branch) " Check tag if has_key(a:spec, 'tag') let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) - if a:spec.tag !=# tag + if a:spec.tag !=# tag && a:spec.tag !~ '\*' let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', \ (empty(tag) ? 'N/A' : tag), a:spec.tag) endif @@ -1744,30 +2243,59 @@ function! s:git_validate(spec, check_branch) let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', \ branch, a:spec.branch) endif + if empty(err) + let [ahead, behind] = split(s:lastline(s:system([ + \ 'git', 'rev-list', '--count', '--left-right', + \ printf('HEAD...origin/%s', a:spec.branch) + \ ], a:spec.dir)), '\t') + if !v:shell_error && ahead + if behind + " Only mention PlugClean if diverged, otherwise it's likely to be + " pushable (and probably not that messed up). + let err = printf( + \ "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.', a:spec.branch, ahead, behind) + else + let err = printf("Ahead of origin/%s by %d commit(s).\n" + \ .'Cannot update until local changes are pushed.', + \ a:spec.branch, ahead) + endif + endif + endif endif else let err = 'Not found' endif - return err + return [err, err =~# 'PlugClean'] endfunction function! s:rm_rf(dir) if isdirectory(a:dir) - call s:system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(a:dir)) + return s:system(s:is_win + \ ? 'rmdir /S /Q '.plug#shellescape(a:dir) + \ : ['rm', '-rf', a:dir]) endif endfunction function! s:clean(force) call s:prepare() - call append(0, 'Searching for unused plugins in '.g:plug_home) + call append(0, 'Searching for invalid plugins in '.g:plug_home) call append(1, '') " List of valid directories let dirs = [] + let errs = {} let [cnt, total] = [0, len(g:plugs)] for [name, spec] in items(g:plugs) - if !s:is_managed(name) || empty(s:git_validate(spec, 0)) + if !s:is_managed(name) call add(dirs, spec.dir) + else + let [err, clean] = s:git_validate(spec, 1) + if clean + let errs[spec.dir] = s:lines(err)[0] + else + call add(dirs, spec.dir) + endif endif let cnt += 1 call s:progress_bar(2, repeat('=', cnt), total) @@ -1777,7 +2305,7 @@ function! s:clean(force) let allowed = {} for dir in dirs - let allowed[s:dirpath(fnamemodify(dir, ':h:h'))] = 1 + let allowed[s:dirpath(s:plug_fnamemodify(dir, ':h:h'))] = 1 let allowed[dir] = 1 for child in s:glob_dir(dir) let allowed[child] = 1 @@ -1791,38 +2319,82 @@ function! s:clean(force) if !has_key(allowed, f) && isdirectory(f) call add(todo, f) call append(line('$'), '- ' . f) + if has_key(errs, f) + call append(line('$'), ' ' . errs[f]) + endif let found = filter(found, 'stridx(v:val, f) != 0') end endwhile - normal! G + 4 redraw if empty(todo) call append(line('$'), 'Already clean.') else - call inputsave() - let yes = a:force || (input('Proceed? (y/N) ') =~? '^y') - call inputrestore() - if yes - for dir in todo - call s:rm_rf(dir) - endfor - call append(line('$'), 'Removed.') + let s:clean_count = 0 + call append(3, ['Directories to delete:', '']) + redraw! + if a:force || s:ask_no_interrupt('Delete all directories?') + call s:delete([6, line('$')], 1) else - call append(line('$'), 'Cancelled.') + call setline(4, 'Cancelled.') + nnoremap d :set opfunc=delete_opg@ + nmap dd d_ + xnoremap d :call delete_op(visualmode(), 1) + echo 'Delete the lines (d{motion}) to delete the corresponding directories' endif endif - normal! G + 4 + setlocal nomodifiable +endfunction + +function! s:delete_op(type, ...) + call s:delete(a:0 ? [line("'<"), line("'>")] : [line("'["), line("']")], 0) +endfunction + +function! s:delete(range, force) + let [l1, l2] = a:range + let force = a:force + let err_count = 0 + while l1 <= l2 + let line = getline(l1) + if line =~ '^- ' && isdirectory(line[2:]) + execute l1 + redraw! + let answer = force ? 1 : s:ask('Delete '.line[2:].'?', 1) + let force = force || answer > 1 + if answer + let err = s:rm_rf(line[2:]) + setlocal modifiable + if empty(err) + call setline(l1, '~'.line[1:]) + let s:clean_count += 1 + else + delete _ + call append(l1 - 1, s:format_message('x', line[1:], err)) + let l2 += len(s:lines(err)) + let err_count += 1 + endif + let msg = printf('Removed %d directories.', s:clean_count) + if err_count > 0 + let msg .= printf(' Failed to remove %d directories.', err_count) + endif + call setline(4, msg) + setlocal nomodifiable + endif + endif + let l1 += 1 + endwhile endfunction function! s:upgrade() echo 'Downloading the latest version of vim-plug' redraw - let tmp = tempname() + let tmp = s:plug_tempname() let new = tmp . '/plug.vim' try - let out = s:system(printf('git clone --depth 1 %s %s', s:plug_src, tmp)) + let out = s:system(['git', 'clone', '--depth', '1', s:plug_src, tmp]) if v:shell_error return s:err('Error upgrading vim-plug: '. out) endif @@ -1857,15 +2429,16 @@ function! s:status() let unloaded = 0 let [cnt, total] = [0, len(g:plugs)] for [name, spec] in items(g:plugs) + let is_dir = isdirectory(spec.dir) if has_key(spec, 'uri') - if isdirectory(spec.dir) - let err = s:git_validate(spec, 1) + if is_dir + let [err, _] = s:git_validate(spec, 1) let [valid, msg] = [empty(err), empty(err) ? 'OK' : err] else let [valid, msg] = [0, 'Not found. Try PlugInstall.'] endif else - if isdirectory(spec.dir) + if is_dir let [valid, msg] = [1, 'OK'] else let [valid, msg] = [0, 'Not found.'] @@ -1874,7 +2447,7 @@ function! s:status() let cnt += 1 let ecnt += !valid " `s:loaded` entry can be missing if PlugUpgraded - if valid && get(s:loaded, name, -1) == 0 + if is_dir && get(s:loaded, name, -1) == 0 let unloaded = 1 let msg .= ' (not loaded)' endif @@ -1923,7 +2496,6 @@ function! s:is_preview_window_open() wincmd p return 1 endif - return 0 endfunction function! s:find_name(lnum) @@ -1945,7 +2517,7 @@ function! s:preview_commit() let b:plug_preview = !s:is_preview_window_open() endif - let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}') + let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7,9}') if empty(sha) return endif @@ -1955,11 +2527,28 @@ function! s:preview_commit() return endif - execute 'pedit' sha - wincmd P - setlocal filetype=git buftype=nofile nobuflisted modifiable - execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --pretty=medium' sha - normal! gg"_dd + if exists('g:plug_pwindow') && !s:is_preview_window_open() + execute g:plug_pwindow + execute 'e' sha + else + execute 'pedit' sha + wincmd P + endif + setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable + let batchfile = '' + try + let [sh, shellcmdflag, shrd] = s:chsh(1) + let cmd = 'cd '.plug#shellescape(g:plugs[name].dir).' && git show --no-color --pretty=medium '.sha + if s:is_win + let [batchfile, cmd] = s:batchfile(cmd) + endif + execute 'silent %!' cmd + finally + let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd] + if s:is_win && filereadable(batchfile) + call delete(batchfile) + endif + endtry setlocal nomodifiable nnoremap q :q wincmd p @@ -1969,90 +2558,127 @@ function! s:section(flags) call search('\(^[x-] \)\@<=[^:]\+:', a:flags) endfunction +function! s:format_git_log(line) + let indent = ' ' + let tokens = split(a:line, nr2char(1)) + if len(tokens) != 5 + return indent.substitute(a:line, '\s*$', '', '') + endif + let [graph, sha, refs, subject, date] = tokens + let tag = matchstr(refs, 'tag: [^,)]\+') + let tag = empty(tag) ? ' ' : ' ('.tag.') ' + return printf('%s%s%s%s%s (%s)', indent, graph, sha, tag, subject, date) +endfunction + +function! s:append_ul(lnum, text) + call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) +endfunction + function! s:diff() call s:prepare() - call append(0, 'Collecting updated changes ...') - normal! gg - redraw - - let cnt = 0 - for [k, v] in filter(items(g:plugs), '!has_key(v:val[1], "commit")') - if !isdirectory(v.dir) || !s:is_managed(k) + call append(0, ['Collecting changes ...', '']) + let cnts = [0, 0] + let bar = '' + let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)') + call s:progress_bar(2, bar, len(total)) + for origin in [1, 0] + let plugs = reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))')))) + if empty(plugs) continue endif - - let diff = s:system_chomp('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"', v.dir) - if !empty(diff) - call append(1, '') - call append(2, '- '.k.':') - call append(3, map(s:lines(diff), '" ". v:val')) - let cnt += 1 - normal! gg + call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') + for [k, v] in plugs + let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' + let cmd = ['git', 'log', '--graph', '--color=never'] + if s:git_version_requirement(2, 10, 0) + call add(cmd, '--no-show-signature') + endif + call extend(cmd, ['--pretty=format:%x01%h%x01%d%x01%s%x01%cr', range]) + if has_key(v, 'rtp') + call extend(cmd, ['--', v.rtp]) + endif + let diff = s:system_chomp(cmd, v.dir) + if !empty(diff) + let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' + call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) + let cnts[origin] += 1 + endif + let bar .= '=' + call s:progress_bar(2, bar, len(total)) + normal! 2G redraw + endfor + if !cnts[origin] + call append(5, ['', 'N/A']) endif endfor + call setline(1, printf('%d plugin(s) updated.', cnts[0]) + \ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : '')) - call setline(1, cnt == 0 ? 'No updates.' : 'Last update:') - nnoremap :silent! call preview_commit() - nnoremap o :silent! call preview_commit() - nnoremap X :call revert() - normal! gg - setlocal nomodifiable - if cnt > 0 + if cnts[0] || cnts[1] + nnoremap (plug-preview) :silent! call preview_commit() + if empty(maparg("\", 'n')) + nmap (plug-preview) + endif + if empty(maparg('o', 'n')) + nmap o (plug-preview) + endif + endif + if cnts[0] + nnoremap X :call revert() echo "Press 'X' on each block to revert the update" endif + normal! gg + setlocal nomodifiable endfunction function! s:revert() + if search('^Pending updates', 'bnW') + return + endif + let name = s:find_name(line('.')) if empty(name) || !has_key(g:plugs, name) || \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y' return endif - call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch), g:plugs[name].dir) + call s:system('git reset --hard HEAD@{1} && git checkout '.plug#shellescape(g:plugs[name].branch).' --', g:plugs[name].dir) setlocal modifiable normal! "_dap setlocal nomodifiable - echo 'Reverted.' + echo 'Reverted' endfunction -function! s:snapshot(...) abort - let home = get(s:, 'plug_home_org', g:plug_home) - let [type, var, header] = s:is_win ? - \ ['dosbatch', '%PLUG_HOME%', - \ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '', - \ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.home]] : - \ ['sh', '$PLUG_HOME', - \ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '', - \ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]] - +function! s:snapshot(force, ...) abort call s:prepare() - execute 'setf' type - call append(0, header) - call append('$', '') + setf vim + call append(0, ['" Generated by vim-plug', + \ '" '.strftime("%c"), + \ '" :source this file in vim to restore the snapshot', + \ '" or execute: vim -S snapshot.vim', + \ '', '', 'PlugUpdate!']) 1 - redraw - - let dirs = sort(map(values(filter(copy(g:plugs), - \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)')), 'v:val.dir')) - let anchor = line('$') - 1 - for dir in reverse(dirs) - let sha = s:system_chomp('git rev-parse --short HEAD', dir) + let anchor = line('$') - 3 + let names = sort(keys(filter(copy(g:plugs), + \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)'))) + for name in reverse(names) + let sha = s:system_chomp(['git', 'rev-parse', '--short', 'HEAD'], g:plugs[name].dir) if !empty(sha) - call append(anchor, printf('cd %s && git reset --hard %s', - \ substitute(dir, '^\V'.escape(g:plug_home, '\'), var, ''), sha)) + call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha)) redraw endif endfor if a:0 > 0 - let fn = expand(a:1) - let fne = s:esc(fn) + let fn = s:plug_expand(a:1) + if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?')) + return + endif call writefile(getline(1, '$'), fn) - if !s:is_win | call s:system('chmod +x ' . fne) | endif - echo 'Saved to '.a:1 - silent execute 'e' fne + echo 'Saved as '.a:1 + silent execute 'e' s:esc(fn) + setf vim endif endfunction @@ -2071,4 +2697,3 @@ endif let &cpo = s:cpo_save unlet s:cpo_save - diff --git a/vim/templates/skeleton.sh b/vim/templates/skeleton.sh index 0633742..2eeac86 100644 --- a/vim/templates/skeleton.sh +++ b/vim/templates/skeleton.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if which tput >/dev/null 2>&1; then ncolors=$(tput colors) diff --git a/vimrc b/vimrc index 72cd3f2..3c3fe23 100644 --- a/vimrc +++ b/vimrc @@ -134,11 +134,6 @@ Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. s if IsWindows() Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so). else - " Fuzzy search - " @incomplete Test out ctrlp for non-Windows setup. - " Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } - " Plug 'junegunn/fzf.vim' - " @fixme Doesn't do anything under Windows... " Plug 'ervandew/supertab' " Improved autocompletion. endif @@ -332,75 +327,75 @@ imap """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" augroup campoCmds - " Clear all autocmds in the group. - autocmd! + " Clear all autocmds in the group. + autocmd! - " Automatically wrap at N characters. - autocmd FileType gitcommit setlocal colorcolumn=72 - autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length + " Automatically wrap at N characters. + autocmd FileType gitcommit setlocal colorcolumn=72 + autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length - " Spell checking. - autocmd FileType gitcommit,markdown,text setlocal spell + " Spell checking. + autocmd FileType gitcommit,markdown,text setlocal spell - " Jump to last cursor position unless it's invalid or in an event handler. - autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif + " Jump to last cursor position unless it's invalid or in an event handler. + autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif - " Indent HTML

tags. - autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif + " Indent HTML

tags. + autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif - " Properly indent schemes (scheme, racket, etc). - autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt + " Properly indent schemes (scheme, racket, etc). + autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt - " Auto reload VIM when settings changed. - autocmd BufWritePost .vimrc so $MYVIMRC - autocmd BufWritePost *.vim so $MYVIMRC - autocmd BufWritePost ~/.vimrc.private so $MYVIMRC + " Auto reload VIM when settings changed. + autocmd BufWritePost .vimrc so $MYVIMRC + autocmd BufWritePost *.vim so $MYVIMRC + autocmd BufWritePost ~/.vimrc.private so $MYVIMRC - function! s:RunCtags() - " The ampersand at the end is to make this run in the background. I had to - " group the commands in parens to make the chained commands run in the - " background. - let l:ctags_cmd = "!(ctags --c-types=+l --c++-types=+l --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.git --exclude=.cache " . g:campo_custom_ctags_args . " -R -o newtags; mv newtags tags) &" - exec l:ctags_cmd | redraw! - endfun - " Generate ctags on save. - " Also Include local variables for C-like languages. - autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h silent! :call RunCtags() + function! s:RunCtags() + " The ampersand at the end is to make this run in the background. I had to + " group the commands in parens to make the chained commands run in the + " background. + let l:ctags_cmd = "!(ctags --c-types=+l --c++-types=+l --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.git --exclude=.cache " . g:campo_custom_ctags_args . " -R -o newtags; mv newtags tags) &" + exec l:ctags_cmd | redraw! + endfun + " Generate ctags on save. + " Also Include local variables for C-like languages. + autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h silent! :call RunCtags() - " Remove trailing whitespace when saving any file. - function! s:StripTrailingWhitespaces() - if g:campo_strip_trailing_whitespace - let l = line(".") - let c = col(".") - %s/\s\+$//e - call cursor(l, c) - endif - endfun - autocmd BufWritePre * :call StripTrailingWhitespaces() + " Remove trailing whitespace when saving any file. + function! s:StripTrailingWhitespaces() + if g:campo_strip_trailing_whitespace + let l = line(".") + let c = col(".") + %s/\s\+$//e + call cursor(l, c) + endif + endfun + autocmd BufWritePre * :call StripTrailingWhitespaces() - "//////////////////////////////////////////////////////////////// - " FILE TEMPLATES - "//////////////////////////////////////////////////////////////// + "//////////////////////////////////////////////////////////////// + " FILE TEMPLATES + "//////////////////////////////////////////////////////////////// - " Shell script template. - autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh - autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan + " Shell script template. + autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh + autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan - " C/C++ template. - autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%") - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d") - autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y") - function! s:InsertHeaderGates() - let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") - execute "normal! ggO#ifndef " . gatename - normal! Go - normal! Go - execute "normal! Go#define " . gatename . " " - execute "normal! o#endif" - normal! kkk - endfunction - autocmd bufnewfile *.{h,hpp} call InsertHeaderGates() + " C/C++ template. + autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice + autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%") + autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d") + autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y") + function! s:InsertHeaderGates() + let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") + execute "normal! ggO#ifndef " . gatename + normal! Go + normal! Go + execute "normal! Go#define " . gatename . " " + execute "normal! o#endif" + normal! kkk + endfunction + autocmd bufnewfile *.{h,hpp} call InsertHeaderGates() augroup END """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -446,16 +441,16 @@ map Q " Open a terminal within vim. Use `exit` to close it. if exists(':terminal') - map t :terminal - tnoremap e - tnoremap h - tnoremap j - tnoremap k - tnoremap l - nnoremap h - nnoremap j - nnoremap k - nnoremap l + map t :terminal + tnoremap e + tnoremap h + tnoremap j + tnoremap k + tnoremap l + nnoremap h + nnoremap j + nnoremap k + nnoremap l endif " Jump to other buffers. @@ -493,7 +488,7 @@ map = z= " Clear the search buffer (highlighting) when hitting return. function! MapCR() - nnoremap :nohlsearch + nnoremap :nohlsearch endfunction call MapCR() nnoremap @@ -514,10 +509,10 @@ nnoremap :%s///g "//////////////////////////////////////////////////////////////// function! s:CompleteFilenameWithoutExtension(ArgLead, CmdLine, CursorPos) - " Returns a matching filename without the period that separates the name - " from the extension. - let l:file = substitute(glob(a:ArgLead.'*', 0, 0), "[\.].*", "", "*") - return l:file + " Returns a matching filename without the period that separates the name + " from the extension. + let l:file = substitute(glob(a:ArgLead.'*', 0, 0), "[\.].*", "", "*") + return l:file endfunction " Custom command to open cpp and h files without typing an extension @@ -681,9 +676,9 @@ let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gr let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray'] function! UpdateRainbowConf() - let g:rainbow_conf = { + let g:rainbow_conf = { \ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow) - \} + \} "\ 'separately': { "\ '*': 0, " Disable all "\ 'c++': {} " Only enable c++ @@ -693,18 +688,18 @@ endfunction call UpdateRainbowConf() function! ReloadRainbow() - if g:campo_theme_use_rainbow_parens - if exists(':RainbowToggle') - call UpdateRainbowConf() - call rainbow#clear() | call rainbow#hook() + if g:campo_theme_use_rainbow_parens + if exists(':RainbowToggle') + call UpdateRainbowConf() + call rainbow#clear() | call rainbow#hook() + endif + else + let g:rainbow_active = 0 + if exists(':RainbowToggle') + call UpdateRainbowConf() + call rainbow#clear() + endif endif - else - let g:rainbow_active = 0 - if exists(':RainbowToggle') - call UpdateRainbowConf() - call rainbow#clear() - endif - endif endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -731,19 +726,19 @@ set tags+=tags;$HOME " CENTER THE BUFFER "//////////////////////////////////////////////////////////////// - function! CenterPane() - " centers the current pane as the middle 2 of 4 imaginary columns - " should be called in a window with a single pane - " Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim - lefta vnew - wincmd w - exec 'vertical resize '. string(&columns * 0.75) - endfunction +function! CenterPane() + " centers the current pane as the middle 2 of 4 imaginary columns + " should be called in a window with a single pane + " Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim + lefta vnew + wincmd w + exec 'vertical resize '. string(&columns * 0.75) +endfunction nnoremap c :call CenterPane() function! RemoveCenterPane() - wincmd w - close + wincmd w + close endfunction nnoremap cw :call RemoveCenterPane() @@ -772,24 +767,24 @@ map l :call ChangeBgTheme('light', 0) map ll :call ChangeBgTheme('dark', 0) function! ChangeBgTheme(bg, onlySetTheme) - if a:bg =~ 'light' - let s:rainbow_theme = 'light' - let s:theme = g:campo_light_theme - exe 'colorscheme ' . s:theme - set background=light - else - let s:rainbow_theme = 'dark' - let s:theme = g:campo_dark_theme - " We have to set the theme twice in order to get its correct dark-theme colors. - " Weird stuff. - exe 'colorscheme ' . s:theme - set background=dark - exe 'colorscheme ' . s:theme - endif + if a:bg =~ 'light' + let s:rainbow_theme = 'light' + let s:theme = g:campo_light_theme + exe 'colorscheme ' . s:theme + set background=light + else + let s:rainbow_theme = 'dark' + let s:theme = g:campo_dark_theme + " We have to set the theme twice in order to get its correct dark-theme colors. + " Weird stuff. + exe 'colorscheme ' . s:theme + set background=dark + exe 'colorscheme ' . s:theme + endif - if !a:onlySetTheme - exec ':AirlineTheme ' . a:bg - endif + if !a:onlySetTheme + exec ':AirlineTheme ' . a:bg + endif endfunction if s:default_bg =~ 'light' @@ -878,35 +873,35 @@ set errorformat+=\\\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m set errorformat+=\\\ %#%f(%l\\\,%c-%*[0-9]):\ %#%t%[A-z]%#\ %m function! HideBuildResultsAndClearErrors() - RemoveErrorMarkers - call asyncrun#quickfix_toggle(g:quickfix_window_height, 0) + RemoveErrorMarkers + call asyncrun#quickfix_toggle(g:quickfix_window_height, 0) endfunction function! HideAsyncResults() - call asyncrun#quickfix_toggle(g:quickfix_window_height, 0) + call asyncrun#quickfix_toggle(g:quickfix_window_height, 0) endfunction function! ToggleBuildResults() - call asyncrun#quickfix_toggle(g:quickfix_window_height) + call asyncrun#quickfix_toggle(g:quickfix_window_height) endfunction function! StopRunTask() - AsyncStop - call HideAsyncResults() + AsyncStop + call HideAsyncResults() endfunction function! ExecuteRunScript() - exec "AsyncRun! -post=call\\ StopRunTask() ./run %" + exec "AsyncRun! -post=call\\ StopRunTask() ./run %" endfunction function! SilentBuild() - AsyncStop - exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* %" + AsyncStop + exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* %" endfunction " Show results window the moment the async job starts augroup vimrc - autocmd User AsyncRunStart call asyncrun#quickfix_toggle(g:quickfix_window_height, 1) + autocmd User AsyncRunStart call asyncrun#quickfix_toggle(g:quickfix_window_height, 1) augroup END " Toggle build results @@ -939,35 +934,23 @@ nnoremap :cp " SEARCH """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" @incomplete -if !IsWindows() - let rg_args = "--column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --pretty \"always\" " . g:campo_custom_search_args - let cmd = "command! -bang -nargs=* Find call fzf#vim#grep('rg " . rg_args . "'.shellescape(), 1, 0)" - exec cmd -endif - " Search using ripgrep (first install with Rust: cargo install ripgrep). function! Search(case_sensitive) - let helper = "[" . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "] search: " - let term = input(helper) - if empty(term) - return - endif + let l:helper = "[" . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "] search: " + let l:term = input(l:helper) + if empty(l:term) + return + endif - "@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the - "quickfix window doesn't seem to parse the ansi color codes. - let rg_args = "--trim -g \"!tags\" " . g:campo_custom_search_args + "@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the + "quickfix window doesn't seem to parse the ansi color codes. + let l:rg_args = "--column --line-number --no-heading --fixed-strings --no-ignore --hidden --follow --trim -g \"!tags\" " . g:campo_custom_search_args - if !a:case_sensitive - let rg_args .= " --ignore-case" - endif + if !a:case_sensitive + let l:rg_args .= " --ignore-case" + endif - if IsWindows() - exec 'Rg ' . rg_args . ' "' . term . '"' - else - " @incomplete Test out ripgrep on non-Windows OS - echo "Not implemented" - endif + exec 'Rg ' . l:rg_args . ' "' . l:term . '"' endfunction map s :call Search(0) map ss :call Search(1) @@ -978,45 +961,44 @@ map ss :call Search(1) nnoremap o (&buftype is# "quickfix" ? "\|:lopen" : "o") nnoremap p (&buftype is# "quickfix" ? "\|:copen" : "p") - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " SEARCH & REPLACE """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Replace the selected text in all files within the repo. function! GlobalReplaceIt(confirm_replacement) - if exists(':Ggrep') - call inputsave() + if exists(':Ggrep') + call inputsave() - if a:confirm_replacement - let l:term = input('Enter search term (w/ confirmation): ') + if a:confirm_replacement + let l:term = input('Enter search term (w/ confirmation): ') + else + let l:term = input('Enter search term (no confirmation): ') + endif + + call inputrestore() + if empty(l:term) + return + endif + + call inputsave() + let l:replacement = input('Enter replacement: ') + call inputrestore() + if empty(l:replacement) + return + endif + + if a:confirm_replacement + let l:confirm_opt = 'c' + else + let l:confirm_opt = 'e' + endif + + execute 'Ggrep '.l:term + execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update' else - let l:term = input('Enter search term (no confirmation): ') + echo "Unable to search since you're not in a git repo" endif - - call inputrestore() - if empty(l:term) - return - endif - - call inputsave() - let l:replacement = input('Enter replacement: ') - call inputrestore() - if empty(l:replacement) - return - endif - - if a:confirm_replacement - let l:confirm_opt = 'c' - else - let l:confirm_opt = 'e' - endif - - execute 'Ggrep '.l:term - execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update' - else - echo "Unable to search since you're not in a git repo" - endif endfunction map r :call GlobalReplaceIt(0) map rr :call GlobalReplaceIt(1) diff --git a/windows/readme.md b/windows/readme.md index b554b19..481613a 100644 --- a/windows/readme.md +++ b/windows/readme.md @@ -159,7 +159,7 @@ processor time and is generally useless. ### Setting up Custom Search -* First install Rusto. See `Setting up Rust` below. +* First install Rust. See `Setting up Rust` below. * Setup `ripgrep`: * Open an `msvc x64` shell and run `cargo install ripgrep`. **Note** the last time I did this I got linker errors saying that it was trying to link an x86 exe in a 64-bit env. I had to run diff --git a/zlogin b/zlogin index d006bd8..b9de118 100644 --- a/zlogin +++ b/zlogin @@ -1,11 +1,7 @@ -# go to saved path if there is one -if [[ -f ~/.current_path~ ]]; then - cd `cat ~/.current_path~` - rm ~/.current_path~ -fi - -# Need to edit the path again here so that we can get the homebrew bin folder ahead of -# everything else. This is necessary because zsh is modifying the path in zshrc, and -# that causes us to run out of /usr/bin for programs that we want to use from homebrew's -# bin -path=($HOME/homebrew/opt/openssl/bin $HOME/homebrew/sbin $HOME/homebrew/bin $path) +# Need to edit the path again here so that we can get the homebrew bin folder +# ahead of everything else. This is necessary because zsh is modifying the path +# in zshrc, and that causes us to run out of /usr/bin for programs that we want +# to use from homebrew's bin +# +# Update 2020-07-25: This no longer seems to be an issue. +#path=(/usr/local/bin /usr/local/sbin /usr/local/opt/openssl/bin $path) diff --git a/zprofile b/zprofile deleted file mode 100644 index fed5738..0000000 --- a/zprofile +++ /dev/null @@ -1 +0,0 @@ -source ~/.zshrc diff --git a/zshenv b/zshenv index db059ff..518a754 100644 --- a/zshenv +++ b/zshenv @@ -1,10 +1,4 @@ platform=`uname -s` -kernel_release=`uname -r` - -test -f ~/.aliases.private && . ~/.aliases.private -# Common env must come first. -test -f ~/.private-dotfiles.common/env && . ~/.private-dotfiles.common/env -test -f ~/.private-dotfiles/env && . ~/.private-dotfiles/env # Unbreak broken, non-colored terminal export TERM=xterm-256color @@ -17,11 +11,10 @@ export HOMEBREW_NO_ANALYTICS=1 export HOMEBREW_NO_INSECURE_REDIRECT=1 export HOMEBREW_CASK_OPTS=--require-sha -# Grep tweaks -export GREP_OPTIONS="-nRi --color --exclude-dir=.git --exclude-dir=tmp --exclude-dir=log --exclude-dir=node_modules --exclude-dir=bower_components --exclude-dir=coverage --exclude-dir=.bundle --exclude=*.csv --exclude=*.pdf --exclude-dir=vendor --exclude-dir=rdoc --exclude-dir=target --exclude-dir=personal --exclude-dir=resources/public/js/*.*" # --exclude-dir=images --exclude-dir=coverage - +# Ruby export RBENV_PATH="$HOME/.rbenv" +# Clojure export LEIN_FAST_TRAMPOLINE=y if [[ $platform == 'Linux' ]]; then @@ -32,16 +25,6 @@ if [[ $platform == 'Linux' ]]; then export LOLCOMMITS_DIR="/shared/Dev/lolcommits" fi -path=($HOME/bin $HOME/.dotfiles/bin ${RBENV_PATH}/bin $HOME/.vim/scripts $path) - -if [[ $platform == 'Darwin' ]]; then - test -f $HOME/.cargo && source $HOME/.cargo/env - # TODO: test for qt - if [ -d "$HOME/Qt" ]; then - path=($HOME/Qt/5.8/clang_64/bin $path) - fi -fi - if [ -d "$HOME/.rbenv" ]; then # Start rbenv eval "$(rbenv init -)" diff --git a/zshrc b/zshrc index d17528d..01126a2 100644 --- a/zshrc +++ b/zshrc @@ -90,8 +90,19 @@ bindkey -e source $ZSH/lib/*.zsh # Source my custom files after oh-my-zsh so I can override things. -source $HOME/.env.platform -source $HOME/.aliases +test -f $HOME/.aliases && . $HOME/.aliases +test -f $HOME/.aliases.private && . $HOME/.aliases.private +# Common env must come first. +test -f $HOME/.private-dotfiles.common/env && . $HOME/.private-dotfiles.common/env +test -f $HOME/.private-dotfiles/env && . $HOME/.private-dotfiles/env + +if [[ -d "$HOME/bin" ]]; then + export PATH=$HOME/bin/:$PATH +fi + +if [[ -d "$HOME/.dotfiles/bin" ]]; then + export PATH=$HOME/.dotfiles/bin/:$PATH +fi # Fix in neovim infocmp $TERM | sed 's/kbs=^[hH]/kbs=\\177/' > $HOME/.$TERM.ti