-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·57 lines (45 loc) · 1.28 KB
/
init.sh
File metadata and controls
executable file
·57 lines (45 loc) · 1.28 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
#!/usr/bin/env bash
if [[ "$(uname -s)" == "Darwin" ]] && ! hash brew && ! hash realpath; then
if ! hash brew; then
echo "You need homebrew and coreutil"
exit 1
fi
if ! hash realpath; then
echo "You need the coreutils"
exit 1
fi
fi
MYPATH="$(dirname "$(realpath "$0")")"
function createLink() {
local environment="$2"
if [[ -z "$environment" ]]; then
echo "Missing environment in createLink call!"
exit 1
fi
mkdir -p "$(dirname ~/"$1")"
ln -s "${MYPATH}/${environment}/$1" ~/"$1"
}
function stowEnvironment() {
local environment="$1"
for f in "${MYPATH}/${environment}/"*; do
# skip .config directory
[[ "$(basename "$f")" == .config ]] && continue
# skip if no files match
[[ -e "$f" ]] || continue
createLink "$(basename "$f")" "${environment}"
done
mkdir -p ~/.config
for f in "${MYPATH}/${environment}/.config/"*; do
# skip if no files match
[[ -e "$f" ]] || continue
createLink ".config/$(basename "$f")" "${environment}"
done
}
stowEnvironment 'global'
stowEnvironment 'agents'
if [[ "$(uname -s)" == "Darwin" ]]; then
stowEnvironment 'osx'
fi
if [[ "$(uname -s)" == "Linux" ]]; then
stowEnvironment 'linux'
fi