-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
111 lines (91 loc) · 1.58 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
#!/usr/bin/env bash
# set -e
echo ""
if [ ! -d $ASDF_DIR ]
then
echo "set"
fi
DOTFILES_ROOT=$(pwd -P)
BACKUP_DIR=$DOTFILES_ROOT/backup
DEBUG_FLAG=true
DRY_FLAG=false
info () {
printf "[info ] \e[1;34m%-6s\e[m\n" "$1"
}
debug () {
if [ $DEBUG_FLAG = true ]
then
printf "[debug] %s\n" "$1"
fi
}
cmd () {
printf "[cmd ] %s\n" "$1"
if [ $DRY_FLAG = false ]
then
eval $1
fi
}
link () {
local src=$1 dst=$2
if [ -e $dst ] && [ ! -h $dst ]
then
backup $dst
fi
if [ -e $dst ]
then
linked=$(readlink $dst)
debug "allready linked: $dst -> $linked"
else
debug "link $dst -> $src"
cmd "ln -s $src $dst"
fi
}
backup () {
debug "backup $1"
cmd "mv $1 $BACKUP_DIR"
}
create_backup_dir () {
if [ -d $BACKUP_DIR ]
then
debug "backup dir $BACKUP_DIR"
else
debug "create backup dir $BACKUP_DIR"
mkdir -p $BACKUP_DIR
fi
}
install_dotfiles () {
info "link dotfiles"
for src in $(find -H "$DOTFILES_ROOT" -name '*.symlink' -not -path '*.git*')
do
dst="$HOME/.$(basename "${src%.*}")"
link "$src" "$dst"
done
}
info "setup dotfiles ..."
debug "DEBUG_FLAG: $DEBUG_FLAG"
debug "DRY_FLAG: $DRY_FLAG"
create_backup_dir
link "$DOTFILES_ROOT/config" "$HOME/.config"
install_dotfiles
case $1 in
brew | "")
source install/brew.sh
;;
brew.mas)
source install/brew.mas.sh
;;
oh-my-zsh | "")
source install/oh-my-zsh.sh
;;
settings | "")
source settings/common.sh
;;
asdf | "")
source settings/asdf.sh
;;
nvim | "")
source settings/nvim.sh
;;
esac
info "... ready"
echo ""