|
18 | 18 | RED='' GREEN='' YELLOW='' BLUE='' CYAN='' DIM='' BOLD='' NC='' |
19 | 19 | fi |
20 | 20 |
|
21 | | -info() { printf ' %b%s%b %s\n' "${BLUE}" "▸" "${NC}" "$1"; } |
22 | | -success() { printf ' %b%s%b %s\n' "${GREEN}" "✓" "${NC}" "$1"; } |
23 | | -warn() { printf ' %b%s%b %s\n' "${YELLOW}" "!" "${NC}" "$1"; } |
24 | | -error() { printf ' %b%s%b %s\n' "${RED}" "✗" "${NC}" "$1" >&2; exit 1; } |
| 21 | +info() { printf ' %b%s%b %b\n' "${BLUE}" "▸" "${NC}" "$1"; } |
| 22 | +success() { printf ' %b%s%b %b\n' "${GREEN}" "✓" "${NC}" "$1"; } |
| 23 | +warn() { printf ' %b%s%b %b\n' "${YELLOW}" "!" "${NC}" "$1"; } |
| 24 | +error() { printf ' %b%s%b %b\n' "${RED}" "✗" "${NC}" "$1" >&2; exit 1; } |
25 | 25 |
|
26 | 26 | banner() { |
27 | 27 | echo "" |
@@ -188,11 +188,46 @@ main() { |
188 | 188 | fi |
189 | 189 |
|
190 | 190 | if [[ -z "$path_binary" ]]; then |
191 | | - echo "" |
192 | | - echo -e " ${DIM}Add to PATH to run rekal from anywhere:${NC}" |
193 | | - echo -e " ${BOLD}export PATH=\"${install_dir}:\$PATH\"${NC}" |
194 | | - echo "" |
195 | | - echo -e " ${DIM}Then run:${NC} ${BOLD}rekal version${NC}" |
| 191 | + # Detect shell profile |
| 192 | + local shell_profile="" |
| 193 | + case "$(basename "${SHELL:-bash}")" in |
| 194 | + zsh) shell_profile="$HOME/.zshrc" ;; |
| 195 | + bash) |
| 196 | + if [[ -f "$HOME/.bash_profile" ]]; then |
| 197 | + shell_profile="$HOME/.bash_profile" |
| 198 | + else |
| 199 | + shell_profile="$HOME/.bashrc" |
| 200 | + fi ;; |
| 201 | + fish) shell_profile="$HOME/.config/fish/config.fish" ;; |
| 202 | + esac |
| 203 | + |
| 204 | + local export_line="export PATH=\"${install_dir}:\$PATH\"" |
| 205 | + |
| 206 | + if [[ -t 0 && -n "$shell_profile" ]]; then |
| 207 | + echo "" |
| 208 | + printf ' %b rekal is not on your PATH. Add it to %b%s%b? [Y/n] ' \ |
| 209 | + "${DIM}▸${NC}" "${BOLD}" "$shell_profile" "${NC}" |
| 210 | + local reply |
| 211 | + read -r reply </dev/tty |
| 212 | + case "$reply" in |
| 213 | + [nN]*) |
| 214 | + echo "" |
| 215 | + echo -e " ${DIM}To add manually:${NC}" |
| 216 | + echo -e " ${BOLD}${export_line}${NC}" |
| 217 | + ;; |
| 218 | + *) |
| 219 | + echo "" >> "$shell_profile" |
| 220 | + echo "# rekal" >> "$shell_profile" |
| 221 | + echo "$export_line" >> "$shell_profile" |
| 222 | + success "Added to ${BOLD}${shell_profile}${NC}" |
| 223 | + info "Run ${BOLD}source ${shell_profile}${NC} or open a new terminal." |
| 224 | + ;; |
| 225 | + esac |
| 226 | + else |
| 227 | + echo "" |
| 228 | + echo -e " ${DIM}Add to PATH to run rekal from anywhere:${NC}" |
| 229 | + echo -e " ${BOLD}${export_line}${NC}" |
| 230 | + fi |
196 | 231 | fi |
197 | 232 |
|
198 | 233 | echo "" |
|
0 commit comments