diff --git a/functions/_fish_deps_detect_pm.fish b/functions/_fish_deps_detect_pm.fish new file mode 100644 index 0000000..a118140 --- /dev/null +++ b/functions/_fish_deps_detect_pm.fish @@ -0,0 +1,13 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Detect the first available system package manager. +function _fish_deps_detect_pm + for pm in paru yay pacman apt brew pkg dnf yum + if type -q $pm + echo $pm + return + end + end + echo "" +end diff --git a/functions/_fish_deps_install.fish b/functions/_fish_deps_install.fish index c549c90..b46679b 100644 --- a/functions/_fish_deps_install.fish +++ b/functions/_fish_deps_install.fish @@ -21,13 +21,13 @@ function _fish_deps_install set -l method_labels # Cargo — only if cargo is present and the tool has a crate - if test -n "$cargo_crate" -a (type -q cargo) + if test -n "$cargo_crate"; and type -q cargo set -a methods cargo set -a method_labels "cargo ($cargo_crate)" end # System PM — only if a PM is detected and the tool is in repos - if test -n "$pm_pkg" -a -n "$pm" + if test -n "$pm_pkg"; and test -n "$pm" set -a methods pm set -a method_labels "$pm ($pm_pkg)" end @@ -44,7 +44,6 @@ function _fish_deps_install set -a methods special-curl set -a method_labels "curl installer" case paru-build - # Only useful on Arch; skip if pacman not present if type -q yay set -a methods special-yay-paru set -a method_labels "yay -S paru" @@ -74,7 +73,7 @@ function _fish_deps_install # Prompt: install this dep? set_color cyan; echo -n "Install $bin? "; set_color normal read -l -P "[Y/n] " _reply - if test "$_reply" = n -o "$_reply" = N + if test "$_reply" = n; or test "$_reply" = N set i (math $i + 1) continue end @@ -89,7 +88,7 @@ function _fish_deps_install set m (math $m + 1) end read -l -P " Choose [1-"(count $methods)"] (default 1): " _choice - if test -n "$_choice" -a "$_choice" -ge 1 -a "$_choice" -le (count $methods) 2>/dev/null + if test -n "$_choice"; and test "$_choice" -ge 1; and test "$_choice" -le (count $methods) set chosen_method $methods[$_choice] end end @@ -106,7 +105,6 @@ function _fish_deps_install curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source fisher update case special-curl - # Currently used for starship if test "$bin" = starship curl -sS https://starship.rs/install.sh | sh end diff --git a/functions/_fish_deps_pm.fish b/functions/_fish_deps_pm.fish deleted file mode 100644 index 9208758..0000000 --- a/functions/_fish_deps_pm.fish +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2026 Rootiest -# SPDX-License-Identifier: AGPL-3.0-or-later - -# Detect the first available system package manager. -function _fish_deps_detect_pm - for pm in paru yay pacman apt brew pkg dnf yum - if type -q $pm - echo $pm - return - end - end - echo "" -end - -# Install a package via the system PM. -# Usage: _fish_deps_pm_install -function _fish_deps_pm_install --argument-names pkg - set -l pm (_fish_deps_detect_pm) - if test -z "$pm" - echo "No supported package manager found." >&2 - return 1 - end - switch $pm - case paru - paru -S --noconfirm $pkg - case yay - yay -S --noconfirm $pkg - case pacman - sudo pacman -S --noconfirm $pkg - case apt - sudo apt install -y $pkg - case brew - brew install $pkg - case pkg - sudo pkg install -y $pkg - case dnf - sudo dnf install -y $pkg - case yum - sudo yum install -y $pkg - end -end - -# Upgrade an already-installed package via the system PM. -# Usage: _fish_deps_pm_upgrade -function _fish_deps_pm_upgrade --argument-names pkg - set -l pm (_fish_deps_detect_pm) - if test -z "$pm" - echo "No supported package manager found." >&2 - return 1 - end - switch $pm - case paru - paru -S --noconfirm $pkg - case yay - yay -S --noconfirm $pkg - case pacman - sudo pacman -S --noconfirm $pkg - case apt - sudo apt install --only-upgrade -y $pkg - case brew - brew upgrade $pkg - case pkg - sudo pkg upgrade -y $pkg - case dnf - sudo dnf upgrade -y $pkg - case yum - sudo yum update -y $pkg - end -end diff --git a/functions/_fish_deps_pm_install.fish b/functions/_fish_deps_pm_install.fish new file mode 100644 index 0000000..7279a07 --- /dev/null +++ b/functions/_fish_deps_pm_install.fish @@ -0,0 +1,28 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Install a package via the system PM. +# Usage: _fish_deps_pm_install +function _fish_deps_pm_install --argument-names pkg + set -l pm (_fish_deps_detect_pm) + if test -z "$pm" + echo "No supported package manager found." >&2 + return 1 + end + switch $pm + case paru yay + $pm -S --noconfirm $pkg + case pacman + sudo pacman -S --noconfirm $pkg + case apt + sudo apt install -y $pkg + case brew + brew install $pkg + case pkg + sudo pkg install -y $pkg + case dnf + sudo dnf install -y $pkg + case yum + sudo yum install -y $pkg + end +end diff --git a/functions/_fish_deps_pm_upgrade.fish b/functions/_fish_deps_pm_upgrade.fish new file mode 100644 index 0000000..0d4efe2 --- /dev/null +++ b/functions/_fish_deps_pm_upgrade.fish @@ -0,0 +1,28 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Upgrade an already-installed package via the system PM. +# Usage: _fish_deps_pm_upgrade +function _fish_deps_pm_upgrade --argument-names pkg + set -l pm (_fish_deps_detect_pm) + if test -z "$pm" + echo "No supported package manager found." >&2 + return 1 + end + switch $pm + case paru yay + $pm -S --noconfirm $pkg + case pacman + sudo pacman -S --noconfirm $pkg + case apt + sudo apt install --only-upgrade -y $pkg + case brew + brew upgrade $pkg + case pkg + sudo pkg upgrade -y $pkg + case dnf + sudo dnf upgrade -y $pkg + case yum + sudo yum update -y $pkg + end +end diff --git a/functions/_fish_deps_update.fish b/functions/_fish_deps_update.fish index e40bcaf..189143b 100644 --- a/functions/_fish_deps_update.fish +++ b/functions/_fish_deps_update.fish @@ -19,7 +19,7 @@ function _fish_deps_update set -l i 1 for bin in $_fdc_bins # Skip fisher itself (handled above) and tools that aren't installed - if test "$bin" = fisher -o not (type -q $bin) + if test "$bin" = fisher; or not type -q $bin set i (math $i + 1) continue end @@ -60,7 +60,7 @@ function _fish_deps_update end # Cargo: prefer for Rust tools - if test -n "$cargo_crate" -a (type -q cargo) + if test -n "$cargo_crate"; and type -q cargo echo "Updating $bin..." cargo install --force $cargo_crate set updated_any 1 @@ -69,7 +69,7 @@ function _fish_deps_update end # System PM fallback - if test -n "$pm_pkg" -a -n "$pm" + if test -n "$pm_pkg"; and test -n "$pm" echo "Updating $bin..." _fish_deps_pm_upgrade $pm_pkg set updated_any 1