From 3a1e638cd8f91b87ceae26599abef3af71d28a42 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Wed, 15 Dec 2021 21:09:50 +0800 Subject: Update vim package update script --- bin/vim-pack | 78 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 28 deletions(-) (limited to 'bin') diff --git a/bin/vim-pack b/bin/vim-pack index 472a9e1..922b45f 100755 --- a/bin/vim-pack +++ b/bin/vim-pack @@ -2,6 +2,9 @@ # package_dirs records directories of all installed packages. It is used # to help clean unused packages. +package_dirs_file=/tmp/my-vim-package-dirs +[ -f $package_dirs_file ] && rm $package_dirs_file + package_dirs=() update_package () { @@ -12,26 +15,42 @@ update_package () { [ $# -ge 3 ] && load_type=$3 package_dir="$HOME/.vim/pack/vendor/$load_type/$name" - package_dirs+=($package_dir) + echo "$package_dir" >> $package_dirs_file if [ ! -d $package_dir ]; then echo "$name : Installing ... " mkdir -p $package_dir - cd $package_dir git clone --depth 1 $remote_url $package_dir && echo "$name : Done" || echo "$name : FAIL" - else - cd $package_dir + fi + + cd $package_dir + git fetch origin > /dev/null + + UPSTREAM='@{u}' + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse "$UPSTREAM") + BASE=$(git merge-base @ "$UPSTREAM") + UPDATED=0 + + if [ $LOCAL != $REMOTE -a $LOCAL = $BASE ]; then echo "$name : Updating ... " git pull && echo "$name : Done" || echo "$name : FAIL" + UPDATED=1 + else + echo "$name : Up to date" fi git submodule update --init --recursive --depth 1 - if [ $# -ge 4 ]; then + if [ $UPDATED -eq 1 -a $# -ge 4 ]; then $4 fi } clean () { + while IFS= read -r line; do + package_dirs+=("$line") + done < $package_dirs_file + for load_type in 'opt' 'start'; do for package_name in $(ls $HOME/.vim/pack/vendor/$load_type); do package_dir=$HOME/.vim/pack/vendor/$load_type/$package_name @@ -56,28 +75,31 @@ install_ycm () { python3 ./install.py $opts } -update_package 'YouCompleteMe' 'git@github.com:ycm-core/YouCompleteMe.git' 'start' 'install_ycm' -update_package "nnn.vim" "git@github.com:mcchrish/nnn.vim.git" -update_package 'vim-fugitive' 'git@github.com:tpope/vim-fugitive.git' -update_package 'fzf' 'git@github.com:junegunn/fzf.git' -update_package 'fzf.vim' 'git@github.com:junegunn/fzf.vim.git' -update_package 'ultisnips' 'git@github.com:SirVer/ultisnips.git' -update_package 'vim-snippets' 'git@github.com:honza/vim-snippets.git' -update_package 'onedark.vim' 'git@github.com:joshdick/onedark.vim.git' 'opt' -update_package undotree git@github.com:mbbill/undotree.git -update_package ale git@github.com:dense-analysis/ale.git -update_package vim-eunuch git@github.com:tpope/vim-eunuch.git -update_package vim-sleuth git@github.com:tpope/vim-sleuth.git -update_package tabular git@github.com:godlygeek/tabular.git -update_package vim-rooter git@github.com:airblade/vim-rooter.git -update_package vim-gutentags git@github.com:ludovicchabant/vim-gutentags.git -update_package vim-airline git@github.com:vim-airline/vim-airline.git -update_package vim-airline-themes git@github.com:vim-airline/vim-airline-themes.git -update_package vim-easymotion git@github.com:easymotion/vim-easymotion.git -update_package editorconfig-vim git@github.com:editorconfig/editorconfig-vim.git -update_package vim-godot git@github.com:habamax/vim-godot.git -update_package vim-ledger git@github.com:ledger/vim-ledger.git -update_package vim-signify git@github.com:mhinz/vim-signify.git -update_package vim-unimpaired git@github.com:tpope/vim-unimpaired.git +update_package 'YouCompleteMe' 'git@github.com:ycm-core/YouCompleteMe.git' 'start' 'install_ycm' & +update_package "nnn.vim" "git@github.com:mcchrish/nnn.vim.git" & +update_package 'vim-fugitive' 'git@github.com:tpope/vim-fugitive.git' & +update_package 'fzf' 'git@github.com:junegunn/fzf.git' & +update_package 'fzf.vim' 'git@github.com:junegunn/fzf.vim.git' & +update_package 'ultisnips' 'git@github.com:SirVer/ultisnips.git' & +update_package 'vim-snippets' 'git@github.com:honza/vim-snippets.git' & +update_package 'onedark.vim' 'git@github.com:joshdick/onedark.vim.git' 'opt' & +update_package undotree git@github.com:mbbill/undotree.git & +update_package ale git@github.com:dense-analysis/ale.git & +update_package vim-eunuch git@github.com:tpope/vim-eunuch.git & +update_package vim-sleuth git@github.com:tpope/vim-sleuth.git & +update_package tabular git@github.com:godlygeek/tabular.git & +update_package vim-rooter git@github.com:airblade/vim-rooter.git & +update_package vim-gutentags git@github.com:ludovicchabant/vim-gutentags.git & +update_package vim-airline git@github.com:vim-airline/vim-airline.git & +update_package vim-airline-themes git@github.com:vim-airline/vim-airline-themes.git & +update_package vim-easymotion git@github.com:easymotion/vim-easymotion.git & +update_package editorconfig-vim git@github.com:editorconfig/editorconfig-vim.git & +update_package vim-godot git@github.com:habamax/vim-godot.git & +update_package vim-ledger git@github.com:ledger/vim-ledger.git & +update_package vim-signify git@github.com:mhinz/vim-signify.git & +update_package vim-unimpaired git@github.com:tpope/vim-unimpaired.git & + +wait +vim '"+helptags ALL"' +q clean -- cgit v1.2.3