-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·72 lines (57 loc) · 1.6 KB
/
install.sh
File metadata and controls
executable file
·72 lines (57 loc) · 1.6 KB
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
#!/bin/bash
bold=$(tput bold)
normal=$(tput sgr0)
color_green="\033[32m"
color_yellow="\033[33m"
color_reset="\033[0m"
function remove_if_exists() {
if [ -f $1 ] || [ -L $1 ]; then
rm $1
echo -e "${bold}Removed${normal} $1"
fi
}
function mkdir_if_not_exists() {
if [ ! -d $1 ]; then
mkdir -p $1
fi
}
function link() {
# usage: link <source paths> <destination paths>
# - <source paths>: relative to directory of this script file.
# - <destination paths>: relative to $HOME
args=($*)
len=`expr $# / 2`
sources=("${args[@]:0:$len}")
destinations=("${args[@]:$len:$len}")
max=`expr $len - 1`
for i in $(seq 0 $max)
do
echo "--------------------------------------------------"
src="$base/${sources[$i]}"
dst="$HOME/${destinations[$i]}"
remove_if_exists "$dst"
mkdir_if_not_exists $(dirname $dst)
ln -s $src $dst
echo -e "${bold}Linked${normal} $color_yellow$src$color_reset"
echo -e " ${bold}to${normal} $color_green$dst$color_reset"
done
}
base=$(cd "$(dirname "$0")" && pwd)
leaves=($(find "$base" -type f \
-not -path "$base/.git/*" \
-not -path "$base/.config/nvim/*" \
-not -name .gitignore \
-not -name install.sh \
-not -name README.md \
-not -name "*.swp"
))
destinations=($(echo "${leaves[@]}" | sed -e "s?$base/??g"))
# sources have same relative path with destinations
link "${destinations[@]}" " ${destinations[@]}"
# nvim
nvim_leaves=($(find "$base/.config/nvim" -type f \
-not -name "*.swp"
))
nvim_destinations=($(echo "${nvim_leaves[@]}" | sed -e "s?$base/??g"))
nvim_sources=($(cat "${nvim_leaves[@]}"))
link "${nvim_sources[@]}" "${nvim_destinations[@]}"