linux-presets/setup.sh

74 lines
1.8 KiB
Bash

#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# Function to install Fish shell
install_fish() {
echo "Installing Fish shell..."
sudo apt update
sudo apt install -y fish
}
# Function to set Fish as the default shell
set_default_fish() {
echo "Setting Fish as the default shell..."
chsh -s $(which fish)
}
# Function to install Starship
install_starship() {
echo "Installing Starship..."
curl -sS https://starship.rs/install.sh | sh -s -- -y
}
# Function to configure Starship for Fish
configure_starship() {
echo "Configuring Starship for Fish..."
mkdir -p ~/.config/fish
echo 'starship init fish | source' >> ~/.config/fish/config.fish
}
# Function to overwrite starship.toml
overwrite_starship_toml() {
local icon="$1"
local starship_toml_path="./terminal/starship.toml"
local destination_path="$HOME/.config/starship.toml"
if [ -f "$starship_toml_path" ]; then
echo "Overwriting starship.toml..."
# Insert icon before hostname if provided
if [ -n "$icon" ]; then
sed -i "s/format = \"\"\"/format = \"\"\"\[ $icon \](fg:color_fg0)\\n/" "$starship_toml_path"
fi
mkdir -p $(dirname "$destination_path")
cp "$starship_toml_path" "$destination_path"
else
echo "starship.toml not found in the repository."
exit 1
fi
}
# Main script execution
install_fish
set_default_fish
install_starship
configure_starship
# Check for the optional icon parameter
icon_param=""
while getopts ":i:" opt; then
case $opt in
i) icon_param="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
overwrite_starship_toml "$icon_param"
echo "Fish shell and Starship prompt setup complete!"