Files

149 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
CHOICE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--fisher) CHOICE="fisher"; shift ;;
--omf) CHOICE="omf"; shift ;;
*) echo "Usage: $0 [--fisher|--omf]"; exit 1 ;;
esac
done
detect_pkg_manager() {
if command -v apt &>/dev/null; then
echo "apt"
elif command -v dnf &>/dev/null; then
echo "dnf"
elif command -v pacman &>/dev/null; then
echo "pacman"
elif command -v zypper &>/dev/null; then
echo "zypper"
else
echo "unknown"
fi
}
install_fish() {
local pm
pm=$(detect_pkg_manager)
case "$pm" in
apt)
sudo apt update && sudo apt install -y fish
;;
dnf)
sudo dnf install -y fish
;;
pacman)
sudo pacman -S --noconfirm fish
;;
zypper)
sudo zypper install -y fish
;;
*)
echo "No supported package manager found. Please install fish manually: https://fishshell.com"
exit 1
;;
esac
}
get_plugins_file() {
local user_plugins="$HOME/.config/fish/fish_plugins"
local repo_plugins="$(dirname "$0")/fish_plugins"
if [ -f "$user_plugins" ]; then
echo "$user_plugins"
elif [ -f "$repo_plugins" ]; then
echo "$repo_plugins"
else
echo ""
fi
}
install_fisher_and_plugins() {
local fisher_path="$HOME/.config/fisher"
local fish_config_dir="$HOME/.config/fish"
echo "Creating Fisher directory structure..."
mkdir -p "$fisher_path"/{functions,completions,conf.d,themes}
echo "Symlinking themes directory..."
mkdir -p "$fish_config_dir"
ln -sf "$fisher_path/themes" "$fish_config_dir/themes"
echo "Installing Fisher plugin manager..."
fish -c 'curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher'
local plugins_file
plugins_file=$(get_plugins_file)
if [ -n "$plugins_file" ]; then
echo "Installing plugins from $(basename "$plugins_file")..."
fish -c "fisher install < $plugins_file"
else
echo "No fish_plugins file found. Skipping plugin installation."
fi
}
install_omf() {
if [ ! -d "$HOME/.local/share/omf" ]; then
echo "Installing Oh My Fish..."
curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install > install
fish install --path=~/.local/share/omf --config=~/.config/omf
else
echo "Oh My Fish already installed."
fi
}
install_bobthefish() {
if command -v fish &>/dev/null && [ -f "$HOME/.local/share/omf/init.fish" ]; then
echo "Installing bobthefish theme..."
fish -c 'omf install bobthefish'
fi
}
set_default_shell() {
local fish_path
fish_path=$(command -v fish)
if [ "$SHELL" != "$fish_path" ]; then
echo "Setting default shell to fish..."
if grep -q "^$USER:" /etc/passwd 2>/dev/null; then
chsh -s "$fish_path"
else
echo "Run this manually: chsh -s $fish_path"
fi
else
echo "Fish is already your default shell."
fi
}
main() {
if [ -z "$CHOICE" ]; then
while true; do
read -p "Select fish plugin manager (fisher/omf): " CHOICE
case "$CHOICE" in
fisher|omf) break ;;
*) echo "Please enter 'fisher' or 'omf'" ;;
esac
done
fi
install_fish
case "$CHOICE" in
fisher)
install_fisher_and_plugins
;;
omf)
install_omf
install_bobthefish
;;
esac
set_default_shell
echo
echo "=== Installation complete ==="
echo "Log out and back in, or run: exec fish"
}
main