-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.zsh
executable file
·83 lines (72 loc) · 1.74 KB
/
install.zsh
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
#!/bin/zsh
files=()
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
RESET='\e[0m'
get_files() {
find . ! '(' -path '*/.git' -prune ')' \
! -path ./install.zsh \
! -path ./README.markdown \
-type f \
-print0
}
link_file() {
file="$1"
dirname=$(dirname "$file")
echo $file
if [[ ! -d $HOME/$dirname ]]
then
mkdir -p "$HOME/$dirname"
fi
# Use hardlink in Cygwin since NTFS does not support symbolic link for file
if [[ $OSTYPE == cygwin ]]
then
ln "$PWD/$file" "$HOME/$file"
else
ln -s "$PWD/$file" "$HOME/$file"
fi
}
cd `dirname $0`
git submodule update --init
while IFS= read -r -d '' file
do
# Strip the "./" prefix
files+=("${file:2}")
done < <(get_files)
for file in "${files[@]}"
do
if [[ ! -e $HOME/$file ]]
then
echo -e "${GREEN}Linking${RESET} ~/$file"
link_file "$file"
continue
fi
if cmp -s "$HOME/$file" "$file"
then
echo -e "${GREEN}Identical${RESET} ~/$file"
rm -rf "$HOME/$file"
link_file "$file"
else
echo -n "Overwrite ~/$file? [yn] "
while read -s -r answer
do
if [[ $answer == [YyNn] ]]
then
[[ $answer == [Yy] ]] && overwrite=0
[[ $answer == [Nn] ]] && overwrite=1
break
fi
done
if [[ $overwrite == 0 ]]
then
echo -e "\n${RED}Renaming${RESET} ~/$file to ~/$file.original"
mv "$HOME/$file" "$HOME/$file.original"
echo -e "\n${GREEN}Linking${RESET} ~/$file"
link_file "$file"
else
echo -e "\n${YELLOW}Skipping${RESET} ~/$file"
fi
fi
done
# vim: set ft=sh: