-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·50 lines (42 loc) · 1.15 KB
/
install
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
#!/bin/bash
set -e
function add_if_not_exists() {
local kind="$1"
local to_add="$2"
local destination="$3"
local binary="$4"
if grep -Fxq "$to_add" "$destination"; then
echo "$binary is already in your path"
return 0
else
echo "Adding $kind..."
echo >> "$destination"
echo "# $kind" >> "$destination"
echo "$to_add" >> "$destination"
fi
}
rcfile="$HOME/.bashrc"
binary=workspace
binary_path_raw="$(realpath "$(dirname $0)")/bin/$binary"
binary_path="${binary_path_raw/#$HOME/\$HOME}"
repo_path_raw="$(dirname "$(dirname "$binary_path")")"
repo_path="${repo_path_raw/#$HOME/\$HOME}"
if [[ ! -f "$rcfile" ]]; then
echo "Couldn't find: $rcfile"
exit 1
fi
add_if_not_exists \
"Auto-reclone for https://github.com/okkays/$binary" \
"[[ ! -d \"$repo_path\" ]] && command -v gh && gh repo clone \"okkays/$binary\" \"$repo_path\"" \
"$rcfile" \
"$binary"
add_if_not_exists \
"Configuration for https://github.com/okkays/$binary" \
"PATH=\"$(dirname $binary_path):\$PATH\"" \
"$rcfile" \
"$binary"
add_if_not_exists \
"Bindings for https://github.com/okkays/$binary" \
". \"$binary_path\"" \
"$rcfile" \
"$binary"