-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·136 lines (121 loc) · 3.24 KB
/
setup.sh
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
#!/bin/bash
DOTFILEREPO="$HOME/dotfiles"
echo "$DOTFILEREPO"
show() {
GLOBIGNORE=".:.."
# shopt -u dotglob
# echo * # all (only non-hidden)
# echo .* # all (only hidden)
shopt -s dotglob
echo "existing bak files:"
ls -l ~/.*bak*
ls -l ~/.config/nvim/*bak*
}
clean() {
echo -n "cleaning..."
rm ~/*bak*
rm ~/.config/nvim/*bak*
echo "clean over"
}
clone() {
echo -e "removing repo $DOTFILEREPO...\n\n"
rm -rf $DOTFILEREPO
git clone git@github.com:ChaosNyaruko/dotfiles.git $DOTFILEREPO
if [[ $? -ne 0 ]]; then
echo "git clone err, exit"
exit 1
fi
}
help() {
echo -e "--show: show removing files\n--clean: cleaing files\n--build: build dotfiles\n--help: show this help"
}
if [[ $1 == "--clean" ]] || [[ $1 == "-c" ]]; then
echo "show and clean..."
show
clean
exit 0
elif [[ $1 == "--list" ]] || [[ $1 == "-l" ]]; then
echo "show removing files"
show
exit 0
elif [[ $1 == "--all" ]] || [[ $1 == "-a" ]]; then
MODE=all
echo "building dotfiles..."
elif [[ $1 == "--screen" ]] || [[ $1 == "-s" ]]; then
MODE=screen
echo "building .screenrc..."
elif [[ $1 == "--git" ]] || [[ $1 == "-g" ]]; then
MODE=git
echo "building .screenrc..."
else
echo -ne "unsupported usage\n"
help
exit 0
fi
VIMRCFILE=$HOME/.vimrc
NVIMFILE=$HOME/.config/nvim
TMUXCONF=$HOME/.config/tmux
SCREENRC=$HOME/.screenrc
GITCONFIG=$HOME/.gitconfig
FISHCONF=$HOME/.config/fish
BATCONF=$HOME/.config/bat
ALACRITTY=$HOME/.config/alacritty
if [ $MODE == "all" ]; then
FILES=($VIMRCFILE $NVIMFILE $TMUXCONF $FISHCONF $BATCONF $ALACRITTY $TMUXCONF)
elif [ $MODE == "screen" ]; then
FILES=($SCREENRC)
elif [ $MODE == "git" ]; then
FILES=($GITCONFIG)
fi
# echo "$FILES" # TODO: only print one? weird, learn it later.
for file in ${FILES[@]}; do
# determine actually dotfile
echo "file:$file"
done
echo -e "\n\n\n"
show
echo -e "\n\n\n"
clean
echo -e "\n\n\n"
clone
echo -e "\n\n\n"
echo "rebuilding dotfiles......"
for file in ${FILES[@]}; do
# determine actually dotfile
DEST=""
if [[ "$file" == "$VIMRCFILE" ]]; then
DEST="$DOTFILEREPO/vimrc"
elif [[ "$file" == "$NVIMFILE" ]]; then
DEST="$DOTFILEREPO/nvim"
elif [[ "$file" == "$TMUXCONF" ]]; then
DEST="$DOTFILEREPO/tmux"
elif [[ "$file" == "$SCREENRC" ]]; then
DEST="$DOTFILEREPO/screenrc"
elif [[ "$file" == "$GITCONFIG" ]]; then
DEST="$DOTFILEREPO/gitconfig"
elif [[ "$file" == "$FISHCONF" ]]; then
DEST="$DOTFILEREPO/fish"
elif [[ "$file" == "$BATCONF" ]]; then
DEST="$DOTFILEREPO/bat"
elif [[ "$file" == "$ALACRITTY" ]]; then
DEST="$DOTFILEREPO/alacritty"
else
echo "error"
exit 1
fi
echo "file: $file, DEST:$DEST"
if [ -L "$file" ] || [ -f "$file" ]; then
# echo "$file exists\n"
t=$(date "+%Y%m%d_%H%M%S")
bakup=${file}"_bak"${t}
echo "baking up $bakup"
cp $file $bakup
rm $file
echo "$file exists, remove it"
else
echo "$file does not exist, creating new one"
fi
# echo "dest: $DEST, sym: $file"
ln -s $DEST $file && echo "set link to dotfiles: $file->$DEST"
echo -e "\n\n\n"
done