-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·64 lines (52 loc) · 1.33 KB
/
Copy pathinstall
File metadata and controls
executable file
·64 lines (52 loc) · 1.33 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
#!/bin/sh
usage() {
cat <<'EOF'
Usage: ./install [rc-file]
Installs these scripts into your shell rc file: adds bin/ and bin/local/
to PATH and sources every file under profile/ and aliases/.
[rc-file] defaults to ~/.zshrc when your shell is zsh, ~/.bashrc when it
is bash, and ~/.profile otherwise. Running the script again is a no-op:
the block is only added once.
EOF
}
case "$1" in
-h | --help)
usage
exit 0
;;
-*)
echo "Unknown option '$1', see './install --help'" >&2
exit 1
;;
esac
if [ $# -gt 1 ]; then
echo "Expected at most one rc-file, see './install --help'" >&2
exit 1
fi
scripts_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
rc=$1
if [ -z "$rc" ]; then
case "${SHELL##*/}" in
zsh) rc=$HOME/.zshrc ;;
bash) rc=$HOME/.bashrc ;;
*) rc=$HOME/.profile ;;
esac
fi
marker="# Jor Scripts"
if [ -f "$rc" ] && grep -qF "$marker" "$rc"; then
echo "Already installed in $rc"
exit 0
fi
block=$(
cat <<EOF
$marker
export PATH="$scripts_dir/bin:$scripts_dir/bin/local:\$PATH"
for f in "$scripts_dir"/profile/*; do . "\$f"; done
for f in "$scripts_dir"/aliases/*; do . "\$f"; done
EOF
)
if ! printf '%s\n' "$block" >>"$rc"; then
echo "Could not write to $rc" >&2
exit 1
fi
echo "Installed in $rc, restart your shell or run: . $rc"