aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/fish/functions/upgrade.fish45
1 files changed, 45 insertions, 0 deletions
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