Skip to content

Commit

Permalink
fix: clean shell name (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean authored Sep 4, 2024
1 parent 80992a6 commit c07ceeb
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions scripts/install_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,73 @@ echo "Detected parent shell: $PARENT_SHELL"
# There are simpler interactive checks such as checking $PS1 or $-,
# but since we are piping the script to sh, these methods don't work
is_interactive_shell() {
# Check if stdin is a terminal
if [ -t 0 ]; then
return 0
fi
# Check if stdout is a terminal
if [ -t 1 ]; then
return 0
fi
# Additional check: see if we can read from /dev/tty
if [ -t 2 ] && [ -r /dev/tty ]; then
return 0
fi
return 1
# Check if stdin is a terminal
if [ -t 0 ]; then
return 0
fi
# Check if stdout is a terminal
if [ -t 1 ]; then
return 0
fi
# Additional check: see if we can read from /dev/tty
if [ -t 2 ] && [ -r /dev/tty ]; then
return 0
fi
return 1
}


# Function to prompt user with Y/n question
prompt_user() {
prompt="$1 [Y/n] "
if is_interactive_shell; then
# Use /dev/tty to read input if available
if [ -r /dev/tty ]; then
printf "%s" "$prompt" > /dev/tty
read -r answer < /dev/tty
else
printf "%s" "$prompt"
read -r answer
fi
else
# No terminal available, use a sensible default
answer="N"
fi
prompt="$1 [Y/n] "
if is_interactive_shell; then
# Use /dev/tty to read input if available
if [ -r /dev/tty ]; then
printf "%s" "$prompt" >/dev/tty
read -r answer </dev/tty
else
printf "%s" "$prompt"
read -r answer
fi
else
# No terminal available, use a sensible default
answer="N"
fi

case "$answer" in
[Nn]*) return 1 ;;
*) return 0 ;;
esac
case "$answer" in
[Nn]*) return 1 ;;
*) return 0 ;;
esac
}

post_install_questions() {
# Optionally skip post-install questions and analytics, used in the playground
if [ -n "$SKIP_KARDINAL_POST_INSTALL" ]; then
return 0
fi
if is_interactive_shell; then
if prompt_user "Would you like to help us improve Kardinal by anonymously reporting your install?"; then
"$BIN_FOLDER/$BINARY_NAME" report-install
else
echo "No problem! Consider giving us a ⭐ on github to help us grow 😊"
fi
else
echo "Non-interactive shell detected. Skipping post-install questions."
fi
# Optionally skip post-install questions and analytics, used in the playground
if [ -n "$SKIP_KARDINAL_POST_INSTALL" ]; then
return 0
fi
if is_interactive_shell; then
if prompt_user "Would you like to help us improve Kardinal by anonymously reporting your install?"; then
"$BIN_FOLDER/$BINARY_NAME" report-install
else
echo "No problem! Consider giving us a ⭐ on github to help us grow 😊"
fi
else
echo "Non-interactive shell detected. Skipping post-install questions."
fi
}

if [ -f "$BIN_FOLDER/$BINARY_NAME" ]; then
if [ $WAS_INTALLED_BEFORE -eq 0 ]; then
case "$PARENT_SHELL" in
-bash | bash)
SHELL_NAME=$(echo "$PARENT_SHELL" | grep -oE '[a-zA-Z]+$')
case "$SHELL_NAME" in
bash)
CONFIG_FILE="$HOME/.bashrc"
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then
handle_error
fi
echo "export PATH=\$PATH:$BIN_FOLDER" >>"$CONFIG_FILE"
echo "source <($BIN_FOLDER/$BINARY_NAME completion bash)" >>"$CONFIG_FILE"
;;
-zsh | zsh)
zsh)
CONFIG_FILE="$HOME/.zshrc"
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then
handle_error
Expand All @@ -120,7 +120,7 @@ if [ -f "$BIN_FOLDER/$BINARY_NAME" ]; then
echo "autoload -U +X compinit && compinit" >>"$CONFIG_FILE"
echo "source <($BIN_FOLDER/$BINARY_NAME completion zsh)" >>"$CONFIG_FILE"
;;
-fish | fish)
fish)
CONFIG_FILE="$HOME/.config/fish/config.fish"
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then
handle_error
Expand All @@ -138,7 +138,7 @@ if [ -f "$BIN_FOLDER/$BINARY_NAME" ]; then
echo ""
echo "> source $CONFIG_FILE"
echo ""
post_install_questions
post_install_questions
else
echo "Kardinal was installed before, just updated it."
echo ""
Expand Down

0 comments on commit c07ceeb

Please sign in to comment.