-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-dotfiles
More file actions
executable file
·90 lines (69 loc) · 1.63 KB
/
Copy pathinstall-dotfiles
File metadata and controls
executable file
·90 lines (69 loc) · 1.63 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
89
90
#!/usr/bin/env bash
printhelp() {
cat <<EOF
Dotfiles installer.
Usage: ./install dotfilesdir installdir
Arguments
dotfilesdir
Directory containing dotfiles which will be linked. It is '\$PWD/dotfiles' by default.
installdir
Directory where dotfiles will be installed. It is home folder by default.
Options
-h, --help
Display this help message.
EOF
}
while [[ $# -ge 1 ]]; do
key="$1"
case $key in
-h|--help)
printhelp
exit 0
;;
*)
;;
esac
shift
done
dotfilesdir=$1
installdir=$2
OS=$(uname)
IS_MACOS=false
IS_LINUX=false
if [[ "${OS}" == "Darwin" ]]; then
IS_MACOS=true
elif [[ "${OS}" == "Linux" ]]; then
IS_LINUX=true
fi
if [[ -z "$dotfilesdir" ]]; then
dotfilesdir=$PWD/dotfiles
fi
if [[ -z "$installdir" ]]; then
installdir=~
fi
echo "--> Installing dotfiles to $installdir"
for dotfile in $(find $dotfilesdir -type f); do
filename=$(basename "$dotfile")
filedir=$(dirname "$dotfile")
filedir="${filedir##$dotfilesdir}"
filedir="${filedir##/}"
if [[ -z "$filedir" ]]; then
dstdir="$installdir"
else
dstdir="$installdir/$filedir"
fi
dstfile="$dstdir/$filename"
if [[ -n "$dstdir" && ! -d "$dstdir" ]]; then
mkdir -p "$dstdir"
fi
if [[ -L "$dstfile" || -f "$dstfile" ]]; then
rm "$dstfile"
fi
relfilepath="$filedir/$filename"
relfilepath="${relfilepath##/}"
echo " $relfilepath"
ln -s "$dotfile" "$dstfile"
done
if [[ "$IS_MACOS" == true ]]; then
ln -s $HOME/Yandex.Disk.localized/.hledger.journal $HOME/.hledger.journal
fi