-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·48 lines (38 loc) · 1.04 KB
/
Copy pathinstall
File metadata and controls
executable file
·48 lines (38 loc) · 1.04 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
#!/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
;;
esac
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
cat >>"$rc" <<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
echo "Installed in $rc, restart your shell or run: . $rc"