From ff1174c60c08b8f22495c109e472d707a3ba25f5 Mon Sep 17 00:00:00 2001 From: Baerspektivo Date: Mon, 22 Jun 2026 17:51:13 +0200 Subject: [PATCH] feat(fish): add update-system function with OS detection and sudo retry --- .config/fish/conf.d/aliases.fish | 1 - .config/fish/functions/update-system.fish | 51 +++++++++++++++++++++++ .gitignore | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .config/fish/functions/update-system.fish diff --git a/.config/fish/conf.d/aliases.fish b/.config/fish/conf.d/aliases.fish index e138912..31576d0 100644 --- a/.config/fish/conf.d/aliases.fish +++ b/.config/fish/conf.d/aliases.fish @@ -4,7 +4,6 @@ alias g="goto" alias vim="nvim" alias code="open -a 'Visual Studio Code'" alias kubi="open -a 'Lens'" -alias update-system="brew update && brew upgrade && npm update -g" alias do-st="docker compose" alias do-re="docker compose down && docker compose up -d" alias hetzi="ssh root@128.140.71.88" diff --git a/.config/fish/functions/update-system.fish b/.config/fish/functions/update-system.fish new file mode 100644 index 0000000..31d5818 --- /dev/null +++ b/.config/fish/functions/update-system.fish @@ -0,0 +1,51 @@ +function update-system --description "Update system packages depending on OS" + # Detect operating system + set -l os (uname -s) + + # Helper function to run commands with sudo password retry + function run_with_sudo + set -l cmd $argv + while true + # Trigger sudo verification. If it succeeds, run the actual command. + if sudo -v + sudo $cmd + return $status + else + echo (set_color red)"Passwort war inkorrekt oder sudo wurde abgebrochen."(set_color normal) + read -l -p "echo 'Möchten Sie es erneut versuchen? (j/N): '" confirm + if not string match -ri '^(j|ja|y|yes)$' "$confirm" + echo "Abgebrochen." + return 1 + end + end + end + end + + if test "$os" = "Darwin" + echo (set_color blue)"[Update-System] macOS erkannt. Starte Homebrew Update..."(set_color normal) + brew update && brew upgrade + + # Optional global npm packages update if npm is installed + if type -q npm + echo (set_color blue)"[Update-System] Aktualisiere globale npm-Pakete..."(set_color normal) + npm update -g + end + else if test -f /etc/arch-release + echo (set_color blue)"[Update-System] Arch Linux erkannt. Starte System-Update..."(set_color normal) + if type -q yay + # yay handles password prompts and elevation internally, so we run it directly + yay -Syu + else + run_with_sudo pacman -Syu + end + else if test -f /etc/debian_version + echo (set_color blue)"[Update-System] Debian/Ubuntu-basiertes System erkannt. Starte System-Update..."(set_color normal) + run_with_sudo apt update; and run_with_sudo apt upgrade -y + else if test -f /etc/fedora-release + echo (set_color blue)"[Update-System] Fedora erkannt. Starte System-Update..."(set_color normal) + run_with_sudo dnf upgrade -y + else + echo (set_color red)"[Update-System] Unbekanntes Betriebssystem. Keine automatische Aktualisierung möglich."(set_color normal) + return 1 + end +end diff --git a/.gitignore b/.gitignore index 158242a..bb8c97e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Brewfile.lock.json .config/fish/fish_variables .config/nvim/lazy-lock.jsonr .gnupg/private-keys-v1.d/* +todo.md