Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·106 lines (88 loc) · 3.29 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·106 lines (88 loc) · 3.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
#
# oosh installer
#
# Usage: curl -fsSL https://raw.githubusercontent.com/bruno-de-queiroz/oosh/main/install.sh | bash
#
set -euo pipefail
OOSH_REPO="${OOSH_REPO:-https://raw.githubusercontent.com/bruno-de-queiroz/oosh/main}"
[[ "$OOSH_REPO" =~ ^https:// ]] || { printf "error: OOSH_REPO must use https://\n" >&2; exit 1; }
OOSH_HOME="${HOME}/.oosh"
# --- colors (respect NO_COLOR) ---
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
B=$'\033[1m' DIM=$'\033[2m' RST=$'\033[0m'
CY=$'\033[36m' GR=$'\033[32m' MG=$'\033[35m' RD=$'\033[31m'
else
B="" DIM="" RST="" CY="" GR="" MG="" RD=""
fi
OK="${GR}✔${RST}" ERR="${RD}✘${RST}" DOT="${MG}◆${RST}"
# --- banner ---
printf "\n${MG}"
printf ' ___ ___ ___ _ \n'
printf ' / _ \ / _ \ / __| | |__ \n'
printf ' | (_) || (_) | \__ \ | _ \\\n'
printf ' \___/ \___/ |___/ |_| |_|\n'
printf "${RST}\n"
printf " ${DOT} ${B}Installing oosh...${RST}\n\n"
# --- sanity check ---
if ! command -v curl >/dev/null 2>&1; then
printf " ${ERR} curl is required but not found\n" >&2
exit 1
fi
# --- download core files ---
mkdir -p "${OOSH_HOME}"
printf " ${CY}↓${RST} oo.sh\n"
curl -fsSL "${OOSH_REPO}/oo.sh" -o "${OOSH_HOME}/oo.sh"
printf " ${CY}↓${RST} generate.sh\n"
curl -fsSL "${OOSH_REPO}/generate.sh" -o "${OOSH_HOME}/generate.sh"
chmod +x "${OOSH_HOME}/generate.sh"
printf " ${CY}↓${RST} trace.sh\n"
curl -fsSL "${OOSH_REPO}/trace.sh" -o "${OOSH_HOME}/trace.sh"
chmod +x "${OOSH_HOME}/trace.sh"
printf " ${CY}↓${RST} lint.sh\n"
curl -fsSL "${OOSH_REPO}/lint.sh" -o "${OOSH_HOME}/lint.sh"
chmod +x "${OOSH_HOME}/lint.sh"
# --- find a writable bin directory ---
_find_bin_dir() {
local d
for d in /opt/homebrew/bin /usr/local/bin; do
[ -d "$d" ] && [ -w "$d" ] && { echo "$d"; return; }
done
echo "${HOME}/.local/bin"
}
BIN_DIR=$(_find_bin_dir)
mkdir -p "${BIN_DIR}"
cat > "${OOSH_HOME}/oosh" << EOF
#!/bin/bash
case "\${1:-}" in
trace) shift; exec bash "${OOSH_HOME}/trace.sh" "\$@" ;;
lint) shift; exec bash "${OOSH_HOME}/lint.sh" "\$@" ;;
*) exec bash "${OOSH_HOME}/generate.sh" "\$@" ;;
esac
EOF
chmod +x "${OOSH_HOME}/oosh"
ln -sf "${OOSH_HOME}/oosh" "${BIN_DIR}/oosh"
printf " ${OK} ${B}oosh${RST} ${DIM}→ ${BIN_DIR}/oosh${RST}\n"
# --- update shell profiles if using ~/.local/bin ---
NEEDS_PATH_UPDATE=0
if [[ "${BIN_DIR}" == "${HOME}/.local/bin" ]]; then
NEEDS_PATH_UPDATE=1
_add_to_profile() {
local file="$1" line='export PATH="${HOME}/.local/bin:${PATH}"'
[ -f "$file" ] || return 0
grep -qF '.local/bin' "$file" || printf '\n# oosh\n%s\n' "$line" >> "$file"
}
_add_to_profile "${HOME}/.bashrc"
_add_to_profile "${HOME}/.bash_profile"
_add_to_profile "${HOME}/.zshrc"
printf " ${OK} PATH updated in shell profiles\n"
fi
# --- done ---
printf "\n ${GR}${B}Done!${RST} ${DIM}Get started:${RST}\n\n"
if [[ "${NEEDS_PATH_UPDATE}" == "1" ]]; then
printf " Reload your shell first:\n"
printf " ${B}source ~/.zshrc${RST} ${DIM}(or ~/.bashrc)${RST}\n\n"
fi
printf " ${B}oosh${RST} ${CY}<name>${RST} ${DIM}generate a new CLI${RST}\n"
printf " ${B}oosh trace${RST} ${CY}<name>${RST} ${DIM}profile tab-completion performance${RST}\n"
printf " ${B}oosh lint${RST} ${CY}<name>${RST} ${DIM}lint annotations and auto-fix with --fix${RST}\n\n"