Skip to content

Commit 652eb46

Browse files
Frank Guoclaude
andcommitted
fix: escape codes in install output, interactive PATH prompt
printf used %s instead of %b for messages containing ANSI escapes, printing raw \033[1m in the terminal. Switch to %b. Add interactive prompt to append PATH export to the user's shell profile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent be1768c commit 652eb46

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

scripts/install.sh

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ else
1818
RED='' GREEN='' YELLOW='' BLUE='' CYAN='' DIM='' BOLD='' NC=''
1919
fi
2020

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; }
2525

2626
banner() {
2727
echo ""
@@ -188,11 +188,46 @@ main() {
188188
fi
189189

190190
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
196231
fi
197232

198233
echo ""

0 commit comments

Comments
 (0)