prompt-themes/bin/install.sh

65 lines
1.7 KiB
Bash
Raw Permalink Normal View History

2025-05-05 16:06:10 +03:00
#!/bin/bash
2025-05-05 16:52:07 +03:00
set -e
2025-05-05 16:06:10 +03:00
2025-05-05 16:52:07 +03:00
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
2025-05-05 23:16:08 +03:00
CONFIG_DIR="$HOME/.config/prompt-themes"
2025-05-05 16:52:07 +03:00
BIN_DIR="$HOME/bin"
2025-05-05 23:16:08 +03:00
TARGET_SCRIPT="$BIN_DIR/prompt-themes.sh"
2025-05-05 16:52:07 +03:00
DEFAULT_CONFIG_SRC="$REPO_DIR/share/_config.yaml"
DEFAULT_CONFIG_DEST="$CONFIG_DIR/config.yaml"
2025-05-05 16:06:10 +03:00
BASHRC="$HOME/.bashrc"
SOURCE_LINE='source "$HOME/bin/prompt-themes.sh"'
2025-05-05 23:16:08 +03:00
echo "🔧 Installing prompt-themes..."
2025-05-05 16:52:07 +03:00
# Check for yq
if ! command -v yq >/dev/null 2>&1; then
echo "❌ Error: 'yq' is not installed."
if [[ "$(uname)" == "Darwin" ]]; then
echo "👉 On macOS, run: brew install yq"
else
echo "👉 On Linux, run: sudo apt install yq (or use your distro's package manager)"
fi
exit 1
2025-05-05 16:06:10 +03:00
fi
2025-05-05 16:52:07 +03:00
# Ensure config dir exists
mkdir -p "$CONFIG_DIR"
# Copy default config if not already present
if [[ ! -f "$DEFAULT_CONFIG_DEST" ]]; then
cp "$DEFAULT_CONFIG_SRC" "$DEFAULT_CONFIG_DEST"
echo "✅ Default config.yaml copied to $DEFAULT_CONFIG_DEST"
2025-05-05 16:06:10 +03:00
else
2025-05-05 16:52:07 +03:00
echo " config.yaml already exists at $DEFAULT_CONFIG_DEST, not overwriting."
2025-05-05 16:06:10 +03:00
fi
2025-05-05 16:52:07 +03:00
# Ensure bin dir exists
mkdir -p "$BIN_DIR"
2025-05-05 23:16:08 +03:00
# Create symlink to prompt-themes.sh using absolute path
SCRIPT_PATH="$REPO_DIR/bin/prompt-themes.sh"
2025-05-05 16:52:07 +03:00
if [[ -L "$TARGET_SCRIPT" || -f "$TARGET_SCRIPT" ]]; then
rm "$TARGET_SCRIPT"
fi
ln -s "$SCRIPT_PATH" "$TARGET_SCRIPT"
echo "✅ Symlink created: $TARGET_SCRIPT$SCRIPT_PATH"
echo "🚀 Done! To apply a theme, run:"
2025-05-05 23:16:08 +03:00
echo " source ~/bin/prompt-themes.sh"
# Add source line to ~/.bashrc if not already present
if ! grep -Fxq "$SOURCE_LINE" "$BASHRC"; then
echo "$SOURCE_LINE" >> "$BASHRC"
echo "✅ Added to ~/.bashrc:"
echo " $SOURCE_LINE"
else
echo " ~/.bashrc already sources prompt-themes.sh"
fi