-
Notifications
You must be signed in to change notification settings - Fork 0
/
linker
executable file
·178 lines (147 loc) · 4.25 KB
/
linker
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
source "./lib/colors"
source "./lib/scripts"
source "./lib/variables"
ignores_global=(
README.md
usr
)
shared_configs_dir="$configs_dir/shared"
shared_config_ignores+=(
"${ignores_global[@]}"
Code
config
idea.properties
oh-my-zsh
)
mac_configs_dir="$configs_dir/mac"
mac_configs_ignores+=(
"${shared_config_ignores[@]}"
karabiner
defaults
override
)
windows_configs_dir="$configs_dir/windows"
windows_configs_ignores+=(
"${shared_config_ignores[@]}"
AppData
)
setEnv() {
case "$(uname -s)" in
CYGWIN*)
export CYGWIN=winsymlinks:native
;;
esac
}
setEnv
linkDotFilesForOs() {
printf "%bLink OS independent dotfiles\n%b" "$Bold" "$Text_Reset"
linkSharedFiles $link
printf "\n"
local uname
uname=$(uname)
# TODO: WSL detection does not work in sudo
if [[ "$uname" == "CYGWIN"* ]] || [[ -n "$WSL_DISTRO_NAME" ]]; then
printf "%bCygwin/WSL based environment detected\n%b" "$Bold" "$Text_Reset"
linkWindowFiles $link
return
fi
if [[ "$uname" == "Darwin"* ]]; then
printf "%bDarwin based environment detected\n%b" "$Bold" "$Text_Reset"
linkMacFiles $link
return
fi
printf "%bNo environment matched%b" "$Red" "$Text_Reset"
}
linkSharedFiles() {
local mode=$1
linkDotFiles "$mode" "$shared_configs_dir" "$target" "shared_config_ignores"
linkFilesInDir "$mode" "$shared_configs_dir/usr/local/bin" "/usr/local/bin"
mkdir -p "$target/.oh-my-zsh/custom"
linkFilesInDir "$mode" "$shared_configs_dir/oh-my-zsh/custom" "$target/.oh-my-zsh/custom"
mkdir -p "$target/.config/git"
linkFile "$mode" "$shared_configs_dir/config/git/ignore" "$target/.config/git/ignore"
linkFile "$mode" "$shared_configs_dir/idea.properties" "$target/idea.properties"
}
linkWindowFiles() {
local mode=$1
linkDotFiles "$mode" "$windows_configs_dir" "$target" "windows_configs_ignores"
linkFilesInDir "$mode" "$windows_configs_dir/usr/local/bin" "/usr/local/bin"
# Custom links
# VSCode
linkFile "$mode" "$shared_configs_dir/Code" "$target/AppData/Roaming/Code"
linkFile "$mode" "$windows_configs_dir/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/settings.json" "$target/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json"
}
linkMacFiles() {
local mode=$1
linkDotFiles "$mode" "$mac_configs_dir" "$target" "mac_configs_ignores"
linkFilesInDir "$mode" "$mac_configs_dir/usr/local/bin" "/usr/local/bin"
# Custom links
linkFile "$mode" "$mac_configs_dir/karabiner" "$target/.config/karabiner"
linkFile "$mode" "$shared_configs_dir/Code" "$target/Library/Application Support/Code"
mkdir -p "$target/.config/nvim"
linkFile "$mode" "$shared_configs_dir/vimrc" "$target/.config/nvim/init.vim"
mkdir -p "$target/Library/Keyboard Layouts"
linkFile "$mode" "$mac_configs_dir/Library/Keyboard Layouts/layout.keylayout" "$target/Library/Keyboard Layouts/layout.keylayout"
# Prevent bell sound when Ctrl+/ is pressed in VSCode
# See: https://stackoverflow.com/a/57651703
mkdir -p "$target/Library/KeyBindings"
linkFile "$mode" "$mac_configs_dir/Library/KeyBindings/DefaultKeyBinding.dict" "$target/Library/KeyBindings/DefaultKeyBinding.dict"
}
clean() {
printf "%bClean OS independent dotfiles\n%b" "$Bold" "$Text_Reset"
linkDotFiles $clean "$shared_configs_dir" "$target" "shared_config_ignores"
printf "\n"
case "$(uname -s)" in
Darwin)
printf "%bDarwin based environment detected\n%b" "$Bold" "$Text_Reset"
linkMacFiles $clean
;;
CYGWIN*)
printf "%bCygwin based environment detected\n%b" "$Bold" "$Text_Reset"
linkWindowFiles $clean
;;
*)
printf "%bNo environment matched\n%b" "$Red" "$Text_Reset"
;;
esac
}
help() {
cat <<-EOF
Usage: linker [COMMAND]
Commands:
ln Link dotfiles based on OS, will replace existing symlinks
clean clean symlinks based on OS
Additional Commands:
ls Link only shared dotfiles
lm Link only Mac dotfiles
lw Link only Windows dotfiles
EOF
}
process() {
case "$1" in
"ln")
linkDotFilesForOs
;;
"ls")
linkSharedFiles $link
;;
"lm")
linkMacFiles
;;
"lw")
linkWindowFiles $link
;;
"clean")
clean
;;
"help")
help
;;
*)
printf "Not a valid command\n\n"
help
;;
esac
}
process "$@"