-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·181 lines (157 loc) · 4.5 KB
/
setup
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env fish
set cmds vimrc vim_plug vim_plugin \
nvim_init nvim_plug nvim_plugin nvim_lua \
oh_my_zsh zshrc \
config.fish fisherman tide_config \
git_config \
tmux spacemacs
if status --is-interactive
complete -x -c setup -a "$cmds"
exit
end
set currentdir (realpath (dirname (status --current-filename)))
function check
echo $argv
eval $argv
set s $status
if not test $s = 0
echo (set_color red)command not return 0, exit...(set_color normal)
exit $s
end
end
function test_not_exist -a dir
if test ! -e $dir
return 0
else
echo -n (set_color -o)"warning: "(set_color normal)
echo `$dir` exists, I will not touch it, and the script may not execute currectly.
return 1
end
end
function ensure_dir -a dir
test_not_exist $dir
and check mkdir -p $dir
end
function try_link -a src dist
test_not_exist $dist; or return
ensure_dir (dirname $dist)
check ln -s $src $dist
end
function vimrc
ensure_dir ~/tmp/vimundo
ensure_dir ~/tmp/vimbackup
try_link $currentdir/vimrc/vimrc ~/.vim/vimrc
end
function nvim_init
ensure_dir ~/.local/share/nvim/undo
echo -n "run "
set_color -o
echo -n "git submodule update --remote"
set_color normal
echo " to acquire latest vim init file"
try_link $currentdir/vimrc/vimrc ~/.config/nvim/init.vim
end
function vim_plug
set path ~/.vim/autoload/plug.vim
test_not_exist $path; or return
check curl -fLo $path --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
end
function vim_plugin
vimrc
vim_plug
try_link $currentdir/vimrc/plugin.vim ~/.vim/plugin.vim
# echo Install Vim plugins...
check 'vim -c \'execute "PlugInstall" | qa\''
end
function nvim_plug
set path ~/.local/share/nvim/site/autoload/plug.vim
test_not_exist $path; or return
check curl -fLo $path --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
end
function nvim_plugin
nvim_init
nvim_plug
set path ~/.config/nvim/layers
ensure_dir $path
for file in $currentdir/vimrc/layers/*
try_link $file $path/(basename $file)
end
set_color -o yellow
echo Please delete unneeded layers in ~/.config/nvim/layers
echo At least delete one of coc.vim or languageclient.vim
echo and run :PlugInstall in nvim.
set_color normal
end
function nvim_lua
ensure_dir ~/.local/share/nvim/undo
echo -n "run "
set_color -o
echo -n "git submodule update --remote"
set_color normal
echo " to acquire latest vim init file"
set path ~/.local/share/nvim/site/pack/packer/start/packer.nvim
if test_not_exist $path
check git clone --depth 1 https://github.com/wbthomason/packer.nvim $path
end
try_link $currentdir/vimrc/init.lua ~/.config/nvim/init.lua
end
function oh_my_zsh
set zpath ~/.antigen
ensure_dir $zpath/antigen
check git clone https://github.com/zsh-users/antigen.git $zpath/antigen/
end
function zshrc
oh_my_zsh
check ln -s $currentdir/zshrc ~/.zshrc
end
function config.fish
try_link $currentdir/config.fish ~/.config/fish/config.fish
end
function fisherman
config.fish
if type -q fisher
echo command fisher exists, skiped
else
echo getting fisherman...
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
end
end
function tide_config
if not type -q tide
echo (set_color red)tide not exists! exit...(set_color normal)
exit 1
end
for name in tide_pwd_truncate_margin
if not set -q -U $name
echo (set_color red)variable \$$name not exists! exit...(set_color normal)
exit 1
end
end
set --universal tide_pwd_truncate_margin 50
end
function git_config
git config --global credential.helper cache
end
function tmux
set path ~/.tmux/plugins/tpm
test_not_exist $path; and check git clone https://github.com/tmux-plugins/tpm $path
check ln -s $currentdir/tmux/theme.conf ~/.tmux/theme.conf
check ln -s $currentdir/tmux.conf ~/.tmux.conf
end
function spacemacs
set path ~/.emacs.d
set url https://github.com/syl20bnr/spacemacs
test_not_exist $path; and check git clone --branch develop $url $path
try_link $currentdir/emacs.d/spacemacs ~/.spacemacs
emacs
end
for cmd in $argv
if contains $cmd $cmds
$cmd
else
echo "Command $cmd doesn't exist"
exit 1
end
end