-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·77 lines (67 loc) · 1.72 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·77 lines (67 loc) · 1.72 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
#!/usr/bin/env sh
set -eu
repo_root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
install_dir=${OCP_INSTALL_DIR:-"$HOME/.local/share/opencode-profiles"}
zshrc=${OCP_ZSHRC:-"$HOME/.zshrc"}
source_path="$install_dir/src/ocp.zsh"
quoted_source_path=$(printf '%s' "$source_path" | sed 's/[\\"$`]/\\&/g')
source_line="source \"$quoted_source_path\""
dry_run=0
write_zshrc=0
usage() {
printf '%s\n' "usage: ./install.sh [--dry-run] [--write-zshrc]"
}
while [ "$#" -gt 0 ]; do
case "$1" in
--dry-run)
dry_run=1
;;
--write-zshrc)
write_zshrc=1
;;
-h|--help)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
shift
done
if [ "$dry_run" -eq 1 ]; then
printf '%s\n' "Would install opencode-profiles to: $install_dir"
printf '%s\n' "Add this line to $zshrc:"
printf '%s\n' "$source_line"
exit 0
fi
mkdir -p "$install_dir/src"
cp "$repo_root/src/ocp.zsh" "$install_dir/src/ocp.zsh"
if [ -f "$repo_root/README.md" ]; then
cp "$repo_root/README.md" "$install_dir/README.md"
fi
if [ -f "$repo_root/LICENSE" ]; then
cp "$repo_root/LICENSE" "$install_dir/LICENSE"
fi
if [ "$write_zshrc" -eq 1 ]; then
mkdir -p "$(dirname -- "$zshrc")"
if [ -f "$zshrc" ]; then
if ! grep -Fqx "$source_line" "$zshrc"; then
cp "$zshrc" "$zshrc.bak"
{
printf '\n'
printf '%s\n' '# opencode-profiles'
printf '%s\n' "$source_line"
} >> "$zshrc"
fi
else
{
printf '%s\n' '# opencode-profiles'
printf '%s\n' "$source_line"
} > "$zshrc"
fi
fi
printf '%s\n' "installed opencode-profiles to: $install_dir"
printf '%s\n' "source it now with: $source_line"
printf '%s\n' "to update $zshrc automatically, rerun with --write-zshrc"