-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot
executable file
·206 lines (175 loc) · 5.07 KB
/
dot
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
options="install diff status"
vim='.vim'
vimplugin='.config/vim/plugged'
list=(
'.config'
'.local'
'.tmux.conf'
)
printUsage()
{
echo "Usage: dot [OPTION]"
echo "OPTIONS:"
echo " install [--config]"
echo " diff [--config]"
echo " status"
}
dotStatus()
{
flag=0
error=0
dotpath=$PWD
echo "Dot status"
# Basic Configuration File
for dir in ${list[@]}; do
files=`find $dir -type f | grep -v "vim"`
for file in $files; do
[ ! -f "$HOME/$file" ] && echo -e " \e[1;31mnonexistent: $file\e[0m" && error=1 && continue
res="`diff $file $HOME/$file`"
if [ "$res" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e "\e[1;31m modified: $file\e[0;37m"
fi
done
done
# Vim Configuration File
if [ ! -d "$HOME/$vim" ]; then
error=1
echo -e " \e[1;31mnonexistent: $vim\e[0m"
else
files=`find $vim -type f | grep -v "\.git"`
for file in $files; do
if [ ! -f "$HOME/$file" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e "\e[1;31m modified: $vim\e[0;37m" && break
fi
res="`diff $file $HOME/$file`"
if [ "$res" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e "\e[1;31m modified: $vim\e[0;37m" && break
fi
done
fi
# Vim Plugin Configuration File
for dir in $vimplugin/*; do
if [ ! -d "$HOME/$dir" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e " \e[1;31mnonexistent: $dir\e[0m" && continue
fi
files=`find $dir -type f | grep -v "\.git"`
for file in $files; do
if [ ! -f "$HOME/$file" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e "\e[1;31m modified: $dir\e[0;37m" && break
fi
res="`diff $file $HOME/$file`"
if [ "$res" ]; then
[ $flag == 0 ] && flag=1 && echo "Changes for dotfiles:"
echo -e "\e[1;31m modified: $dir\e[0;37m" && break
fi
done
done
# Untracked Configuration File
track=0
cd $HOME
if [ -d ${list[0]} ]; then
for dir in ${list[0]}/*; do
if [ ! -d $dotpath/$dir ]; then
[ $track == 0 ] && track=1 && echo && echo "Untracked configuration:"
echo -e "\e[1;31m $dir\e[0;37m"
fi
done
fi
[ $flag == 0 -a $track == 0 -a $error == 0 ] && echo "all same"
}
diffFile()
{
res="`diff $1 $2`"
if [ "$res" ]; then
if type diff-so-fancy >/dev/null 2>&1; then
echo && (diff -ru $1 $2 | diff-so-fancy)
else
diff -ru $1 $2
fi
fi
}
dotDiff()
{
echo "Dot diff"
# Basic Configuration File
for dir in ${list[@]}; do
files=`find $dir -type f | grep -v "vim"`
for file in $files; do
[ ! -f "$HOME/$file" ] && echo -e " \e[1;31mnonexistent: $file\e[0m" && continue
diffFile $file $HOME/$file
done
done
if [ "$1" == "--config" ]; then
return
fi
# Vim Configuration File
if [ ! -d $HOME/$vim ]; then
echo -e " \e[1;31mnonexistent: $vim\e[0m"
else
files=`find $vim -type f | grep -v "\.git"`
for file in $files; do
[ ! -f "$HOME/$file" ] && echo -e " \e[1;31mnonexistent: $file\e[0m" && continue
diffFile $file $HOME/$file
done
fi
# Vim Plugin Configuration File
if [ ! -d "$HOME/$vimplugin" ]; then
echo -e " \e[1;31mnonexistent: $vimplugin\e[0m"
else
for dir in $vimplugin/*; do
[ ! -d "$HOME/$dir" ] && echo -e " \e[1;31mnonexistent: $dir\e[0m" && continue
files=`find $dir -type f | grep -v "\.git"`
for file in $files; do
[ ! -f "$HOME/$file" ] && echo -e " \e[1;31mnonexistent: $file\e[0m" && continue
diffFile $file $HOME/$file
done
done
fi
}
dotInstall()
{
echo "Dot install"
# Basic Configuration File
for dir in ${list[@]}; do
if [ "$1" == "--config" ]; then
rsync -av --exclude='vim/' $dir $HOME
else
rsync -av $dir $HOME
fi
[ $? == 0 ] && echo "$dir install done"
done
if [ "$1" == "--config" ]; then
return
fi
# Vim Configuration File
rsync -av $vim $HOME
find $HOME/$vim -name "\.git" | xargs rm -rf
find $HOME/$vimplugin -name "\.git" | xargs rm -rf
[ $? == 0 ] && echo "$vim install done"
}
if [ $# -lt 1 ]; then
printUsage
exit 1
fi
case $1 in
status)
dotStatus
;;
diff)
dotDiff $2
;;
install)
dotInstall $2
;;
*)
echo "error: wrong option" && echo
printUsage
exit 2
;;
esac