-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·89 lines (73 loc) · 2.12 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·89 lines (73 loc) · 2.12 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
SCRIPT_DIR=
SCRIPT_PATH=$(readlink -e -- "$0")
if [ $? -ne 0 ]; then
echo "readlink didn't work, we assume dotfiles dir to be pwd (make sure that's right!)"
echo "pwd: $PWD"
SCRIPT_DIR=$PWD
else
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
fi
cd "$SCRIPT_DIR"
T_HOME=$HOME
EXCLUDE_PAT='(^install\.sh$)|(^df\.sh$)|(^README\.md$)|(^\.linked_dirs$)|(^.*\.swp$)'
force_=0
if [ "$1" = "-f" ]; then
force_=1
echo "Running with -f, files will be overwritten."
fi
# confirm home dir
echo -n "Install dotfiles to \"$T_HOME\". OK? (y/N) "
read -r yn
if [[ ! $yn =~ ^[Yy]$ ]]; then
echo "Abort."
exit 1
fi
# link files
ls -Ap | grep -v / | while read -r p; do
echo $p
if [[ $p =~ $EXCLUDE_PAT ]]; then
continue
fi
echo "\"$T_HOME/$p\""
if [ -e "$T_HOME/$p" ] || [ -L "$T_HOME/$p" ]; then
if [ $force_ -eq 1 ]; then
echo "force: File $T_HOME/$p already exists. Remove and link."
rm "$T_HOME/$p"
else
if [ -L "$T_HOME/$p" ]; then
echo "File $p already exist symbolicly. Probably already linked. Skip."
continue
fi
echo "File $p already exists, and is not symbolic. Run with -f to overwrite."
continue
fi
fi
ln -s "$SCRIPT_DIR/$p" "$T_HOME/$p" && echo "(Link) $SCRIPT_DIR/$p <-> $T_HOME/$p"
done
# link dirs
while read -r p; do
if [ -e "$T_HOME/$p" ] || [ -L "$T_HOME/$p" ]; then
if [ $force_ -eq 1 ]; then
echo "force: Dir $T_HOME/$p already exists. Remove and link."
rm -r "$T_HOME/$p"
else
if [ -L "$T_HOME/$p" ]; then
echo "Dir $p already exist symbolicly. Probably already linked. Skip."
continue
fi
echo "Dir $p already exists, and is not symbolic. Run with -f to overwrite."
continue
fi
fi
mkdir -p $(dirname "$T_HOME/$p")
ln -s "$SCRIPT_DIR/$p" "$T_HOME/$p" && echo "(Link) $SCRIPT_DIR/$line <-> $T_HOME/$line"
done < .linked_dirs
# include .gitconfig.common if applicable
touch ~/.gitconfig
if [ -e "$SCRIPT_DIR/.gitconfig.common" ] && ! cat "$T_HOME/.gitconfig" | grep -q "~/.gitconfig.common" ; then
echo "Include .gitconfig.common"
printf "[include]\n" >> "$T_HOME/.gitconfig"
printf "\tpath = ~/.gitconfig.common\n" >> "$T_HOME/.gitconfig"
fi
echo "Done."