-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-common.sh
executable file
·72 lines (59 loc) · 1.58 KB
/
config-common.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
#!/bin/bash
print_success() {
printf "\e[0;32m [✔] %s\e[0m\n" "$1"
}
print_error() {
printf "\e[0;31m [✖] Failed to link %s %s\e[0m\n" "$1" "$2"
}
print_question() {
# Print output in yellow
printf "\e[0;33m [?] %s\e[0m" "$1"
}
execute() {
$1 &> /dev/null
print_result $? "${2:-$1}"
}
print_result() {
if [ "$1" -eq 0 ]; then
print_success "$2"
else
print_error "$2"
fi
[ "$3" == "true" ] && [ "$1" -ne 0 ] && exit
}
ask_for_confirmation() {
print_question "$1 [y/N] "
read -r -n 1
printf "\n"
}
answer_is_yes() {
[[ "$REPLY" =~ ^[Yy]$ ]] \
&& return 0 \
|| return 1
}
link_file() {
local sourceFile=$1
local targetFile=$2
if [ ! -e "$targetFile" ]; then
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
elif [ "$(readlink "$targetFile")" == "$sourceFile" ]; then
print_success "$targetFile → $sourceFile"
else
ask_for_confirmation "'$targetFile' already exists, do you want to overwrite it?"
if answer_is_yes; then
rm -rf "$targetFile"
execute "ln -fs $sourceFile $targetFile" "$targetFile → $sourceFile"
else
print_error "$targetFile → $sourceFile"
fi
fi
}
#ln -sf $(pwd)/git/.gitaliases $HOME/.gitaliases
#ln -sf $(pwd)/bin $HOME
link_file "$(pwd)/fish" "$HOME/.config/fish"
link_file "$(pwd)/vim/.vim" "$HOME/.vim"
link_file "$(pwd)/vim/.vimrc" "$HOME/.vimrc"
link_file "$(pwd)/bash/.bash_profile" "$HOME/.bash_profile"
link_file "$(pwd)/bash/.bash_prompt" "$HOME/.bash_prompt"
link_file "$(pwd)/bash/.profile" "$HOME/.profile"
link_file "$(pwd)/bash/.path" "$HOME/.path"