aboutsummaryrefslogtreecommitdiff
path: root/bin/vim-pack
blob: 922b45f631744ca0f09bcd789293c2b170151ed5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash

# 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 () {
    name=$1
    remote_url=$2

    load_type='start'
    [ $# -ge 3 ] && load_type=$3

    package_dir="$HOME/.vim/pack/vendor/$load_type/$name"
    echo "$package_dir" >> $package_dirs_file
    if [ ! -d $package_dir ]; then
        echo "$name : Installing ... "
        mkdir -p $package_dir
        git clone --depth 1 $remote_url $package_dir && echo "$name : Done" || echo "$name : FAIL"
    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 [ $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
            if [[ ! " ${package_dirs[*]} " =~ " ${package_dir} " ]]; then
                read -r -p "rm -rf $package_dir? [y/N]: " response
                response=${response,,}
                if [[ "$response" =~ ^(yes|y)$ ]]; then
                    rm -rf $package_dir
                fi
            fi
        done
    done
}

install_ycm () {
    opts=' --clangd-completer'

    if [ -f /usr/bin/go -o -f /usr/local/bin/go ]; then
        opts="$opts --go-completer"
    fi

    python3 ./install.py $opts
}

update_package 'YouCompleteMe' '[email protected]:ycm-core/YouCompleteMe.git' 'start' 'install_ycm' &
update_package "nnn.vim" "[email protected]:mcchrish/nnn.vim.git" &
update_package 'vim-fugitive' '[email protected]:tpope/vim-fugitive.git' &
update_package 'fzf' '[email protected]:junegunn/fzf.git' &
update_package 'fzf.vim' '[email protected]:junegunn/fzf.vim.git' &
update_package 'ultisnips' '[email protected]:SirVer/ultisnips.git' &
update_package 'vim-snippets' '[email protected]:honza/vim-snippets.git' &
update_package 'onedark.vim' '[email protected]:joshdick/onedark.vim.git' 'opt' &
update_package undotree [email protected]:mbbill/undotree.git &
update_package ale [email protected]:dense-analysis/ale.git &
update_package vim-eunuch [email protected]:tpope/vim-eunuch.git &
update_package vim-sleuth [email protected]:tpope/vim-sleuth.git &
update_package tabular [email protected]:godlygeek/tabular.git &
update_package vim-rooter [email protected]:airblade/vim-rooter.git &
update_package vim-gutentags [email protected]:ludovicchabant/vim-gutentags.git &
update_package vim-airline [email protected]:vim-airline/vim-airline.git &
update_package vim-airline-themes [email protected]:vim-airline/vim-airline-themes.git &
update_package vim-easymotion [email protected]:easymotion/vim-easymotion.git &
update_package editorconfig-vim [email protected]:editorconfig/editorconfig-vim.git &
update_package vim-godot [email protected]:habamax/vim-godot.git &
update_package vim-ledger [email protected]:ledger/vim-ledger.git &
update_package vim-signify [email protected]:mhinz/vim-signify.git &
update_package vim-unimpaired [email protected]:tpope/vim-unimpaired.git &

wait 
vim '"+helptags ALL"' +q

clean