From d483fee544d5731a52a8deec086357d1fa980d49 Mon Sep 17 00:00:00 2001 From: Zane V Date: Sun, 16 Nov 2025 14:12:05 -0500 Subject: [PATCH] Enhance install.sh to support dynamic shell configuration detection - Added logic to detect the user's shell (bash or zsh) and update the appropriate configuration file for PATH modification. - Improved user prompts to reflect the detected shell configuration file. - Implemented checks to prevent duplicate PATH entries and create the configuration file if it doesn't exist. --- install.sh | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 0e249cd..42ebde8 100755 --- a/install.sh +++ b/install.sh @@ -605,22 +605,54 @@ if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then echo "" echo -e "${YELLOW}Warning: $HOME/.local/bin is not in your PATH${NC}" echo "" - echo "To use the 'zdtt' command, add the following line to your ~/.bashrc:" + + # Detect current shell + # Check environment variables first (most reliable) + if [[ -n "$ZSH_VERSION" ]]; then + SHELL_CONFIG="$HOME/.zshrc" + SHELL_NAME="zsh" + elif [[ -n "$BASH_VERSION" ]]; then + SHELL_CONFIG="$HOME/.bashrc" + SHELL_NAME="bash" + else + # Fallback: check $SHELL variable + CURRENT_SHELL="${SHELL##*/}" + if [[ "$CURRENT_SHELL" == "zsh" ]] || [[ "$SHELL" == *"zsh"* ]]; then + SHELL_CONFIG="$HOME/.zshrc" + SHELL_NAME="zsh" + else + # Default to bash if we can't determine + SHELL_CONFIG="$HOME/.bashrc" + SHELL_NAME="bash" + fi + fi + + echo "To use the 'zdtt' command, add the following line to your $SHELL_CONFIG:" echo "" echo " export PATH=\"\$HOME/.local/bin:\$PATH\"" echo "" - echo "Then run: source ~/.bashrc" + echo "Then run: source $SHELL_CONFIG" echo "" # Ask if user wants to add it automatically - read -p "Would you like to add it to your ~/.bashrc now? (y/n) " -n 1 -r + read -p "Would you like to add it to your $SHELL_CONFIG now? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then - echo "" >> "$HOME/.bashrc" - echo "# Added by ZDTT Terminal installer" >> "$HOME/.bashrc" - echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc" - echo -e "${GREEN}✓${NC} Added to ~/.bashrc" - echo "Please run: source ~/.bashrc" + # Create the config file if it doesn't exist + if [ ! -f "$SHELL_CONFIG" ]; then + touch "$SHELL_CONFIG" + fi + + # Check if the PATH line already exists + if ! grep -q 'export PATH="\$HOME/.local/bin:\$PATH"' "$SHELL_CONFIG"; then + echo "" >> "$SHELL_CONFIG" + echo "# Added by ZDTT Terminal installer" >> "$SHELL_CONFIG" + echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$SHELL_CONFIG" + echo -e "${GREEN}✓${NC} Added to $SHELL_CONFIG" + echo "Please run: source $SHELL_CONFIG" + else + echo -e "${GREEN}✓${NC} PATH already configured in $SHELL_CONFIG" + fi fi else echo -e "${GREEN}✓${NC} ~/.local/bin is already in your PATH"