Skip to content

Instantly share code, notes, and snippets.

@maximillianus
Created February 2, 2025 20:19
Show Gist options
  • Save maximillianus/f81e70685edd85ddec8a68b8481275b1 to your computer and use it in GitHub Desktop.
Save maximillianus/f81e70685edd85ddec8a68b8481275b1 to your computer and use it in GitHub Desktop.
Configure starship prompt
#!/bin/bash
# Check if curl is installed
echo "Check if curl is installed..."
if ! command -v curl &> /dev/null; then
echo "curl is not installed. Installing curl..."
if command -v apt &> /dev/null; then
sudo apt update && sudo apt install -y curl
elif command -v dnf &> /dev/null; then
sudo dnf install -y curl
elif command -v yum &> /dev/null; then
sudo yum install -y curl
else
echo "Could not install curl. Please install it manually."
exit 1
fi
fi
# Install Starship
echo "Installing Starship..."
curl -sS https://starship.rs/install.sh | sudo sh -- -y
# Backup existing .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
echo "Backing up existing .bashrc..."
cp "$HOME/.bashrc" "$HOME/.bashrc.backup.$(date +%Y%m%d_%H%M%S)"
fi
# Add Starship initialization to .bashrc if not already present
if ! grep -q "eval \"\$(starship init bash)\"" "$HOME/.bashrc"; then
echo "Adding Starship initialization to .bashrc..."
echo '
# Initialize Starship
eval "$(starship init bash)"' >> "$HOME/.bashrc"
fi
# Create .config directory if it doesn't exist
mkdir -p "$HOME/.config"
# Download starship.toml from gist
# Replace GIST_URL with your actual gist raw URL
GIST_URL="https://gist.githubusercontent.com/maximillianus/58e60aca9240fb00bbdace130f186b1d/raw/85da56b0437055fb31f994732bbdec0c3d415786/starship.toml"
echo "Downloading starship.toml configuration..."
curl -fsSL "$GIST_URL" -o "$HOME/.config/starship.toml"
# Check if download was successful
if [ $? -eq 0 ]; then
echo "Successfully downloaded starship.toml"
else
echo "Failed to download starship.toml. Please check the URL and try again."
exit 1
fi
echo "Installation complete!"
echo "Please restart your terminal or run 'source ~/.bashrc' to start using Starship."
# Optionally source .bashrc immediately
read -p "Would you like to apply the changes now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
source "$HOME/.bashrc"
echo "Starship is now active!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment