-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·55 lines (47 loc) · 955 Bytes
/
install.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
#!/bin/bash
DOTFILES_DIR=".dotfiles"
BACKUP_DIR="backup"
DOTFILES=(
agignore
bash_profile
bashrc
gemrc
gitconfig
gitignore_global
inputrc
irbrc
psqlrc
)
function warn() {
echo "$(tput bold)$(tput setaf 3) *** ${1}$(tput sgr0)"
}
function link(){
for script in ${DOTFILES[@]}; do
dotfile=${HOME}/.${script}
if [[ -f $dotfile ]]; then
warn "~/.${script} already exists"
else
ln -s ${DOTFILES_DIR}/$script $dotfile
fi
done
}
function backup(){
for script in ${DOTFILES[@]}; do
dotfile=${HOME}/.${script}
[[ -f $dotfile && ! -L $dotfile ]] || continue;
backup=${BACKUP_DIR}/${script}
if [[ -f $backup ]]; then
warn "${BACKUP_DIR}/${script} already exists"
else
mv $dotfile $backup
fi
done
}
function backup_dir(){
[[ -d $BACKUP_DIR ]] || mkdir -p $BACKUP_DIR
}
############################################
backup_dir
backup
link
############################################