#!/usr/bin/fish
# Fish shell post-install setup
# Handles: Setting fish as default shell, cleanup of old wrapper scripts

echo "[fish/install] Setting up Fish shell..." >&2

# Clean up old wrapper script from git-based installations
# (DNF installations use /usr/bin/fedpunk instead)
set -l old_wrapper "$HOME/.local/bin/fedpunk"
if test -f "$old_wrapper"
    echo "[fish/install] Removing old wrapper script..." >&2
    rm -f "$old_wrapper"
    echo "[fish/install] ✓ Cleaned up old wrapper" >&2
end

# Get the actual default shell from /etc/passwd
set -l current_shell (getent passwd $USER | cut -d: -f7)
set -l fish_path (type -p fish)

# Set fish as default shell if not already
if test "$current_shell" != "$fish_path"
    echo "[fish/install] Setting fish as default shell..." >&2
    sudo chsh -s $fish_path $USER

    if test $status -eq 0
        echo "[fish/install] ✓ Fish is now your default shell" >&2
        echo "[fish/install]   Please log out and back in for changes to take effect" >&2
    else
        echo "[fish/install] ✗ Failed to set fish as default shell" >&2
        echo "[fish/install]   You may need to run: sudo chsh -s $fish_path $USER" >&2
        exit 1
    end
else
    echo "[fish/install] ✓ Fish is already your default shell" >&2
end

echo "[fish/install] Setup complete" >&2
