-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.sh
More file actions
executable file
·76 lines (60 loc) · 1.75 KB
/
helpers.sh
File metadata and controls
executable file
·76 lines (60 loc) · 1.75 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
#!/usr/bin/env zsh
# Helper to exit and display an error message
die () {
echo
echo $(basename $0): ${1:-"Unknown Error"} 1>&2
exit 1
}
run_installer () {
installer=$1
echo "Running ${installer}"
sh -c "${installer}"
}
set_symlink () {
overwrite_all=${overwrite_all:-false}
backup_all=${backup_all:-false}
skip_all=${skip_all:-false}
local link_target="$1:A" link_file="$2"
local overwrite='' backup='' skip=''
local action=''
if [ -f "$link_file" -o -d "$link_file" -o -L "$link_file" ]; then
if [ "$overwrite_all" = "false" ] && [ "$backup_all" = "false" ] && [ "$skip_all" = "false" ]; then
local current_link_target
current_link_target="$link_file:A"
if [ "$current_link_target" = "$link_target" ]; then
skip=true;
else
echo "⚠️ File already exists: $link_target ($(basename "$link_target")), what do you want to do?\n\
[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?"
read -k action
case "$action" in
o ) overwrite=true;;
O ) overwrite_all=true;;
b ) backup=true;;
B ) backup_all=true;;
s ) skip=true;;
S ) skip_all=true;;
* ) ;;
esac
fi
fi
overwrite="${overwrite:-$overwrite_all}"
backup="${backup:-$backup_all}"
skip="${skip:-$skip_all}"
if [ "$overwrite" = "true" ]; then
rm -rf "$link_file"
echo "Removed $link_file"
fi
if [ "$backup" = "true" ]; then
mv "$link_file" "${link_file}.backup"
echo "Moved $link_file to ${link_file}.backup"
fi
if [ "$skip" = "true" ]; then
echo "Skipped $link_target"
fi
fi
if [ "$skip" != "true" ]; then
ln -s "$1" "$2"
echo "Linked $1 ➠ $2"
fi
}