From 527cc270d660cbfd4076f5ff4af3471988322eea Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 14 Sep 2016 18:57:48 +0200 Subject: add universal package upgrade function It handles: + Arch with AUR (pacaur/yaourt) + Debian --- config/fish/functions/upgrade.fish | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 config/fish/functions/upgrade.fish (limited to 'config') diff --git a/config/fish/functions/upgrade.fish b/config/fish/functions/upgrade.fish new file mode 100644 index 0000000..aace60b --- /dev/null +++ b/config/fish/functions/upgrade.fish @@ -0,0 +1,45 @@ +#TODO update dotfile directory + +function upgrade -d "universal upgrade function" + function is_command -a cmd -d "check if a command is available" + type $cmd >/dev/null 2>/dev/null + end + + function maybe_root -a cmd -d "execute a cmd if it fails try to use sudo" + set res (eval $cmd 2>&1) + # cmd failed + if test $status -gt 0 + # try to guess cause + if string match -r ".*root|permission.*" "$res" + set s_cmd "" + for c in (string split ";" $cmd) + set s_cmd $s_cmd (echo $c | sed -r "s/^ ?(and |or )?/\1sudo /" -) + end + eval (string join ";" $s_cmd) + else + echo "$res" >&2 + return $status + end + end + end + + # Arch + if is_command pacman + if is_command pacaur + pacaur -Syu + else if is_command yaourt + yaourt -Syua + else + maybe_root "pacman -Syu" + end + end + + # Debian based + if is_command apt-get + if is_command apt + maybe_root "apt update; and apt dist-upgrade" + else + maybe_root "apt-get update; and apt-get dist-upgrade" + end + end +end -- cgit v1.2.3