Browse Source

added pkgup script

DanielFGray 2 years ago
parent
commit
4827da7d9b
1 changed files with 59 additions and 0 deletions
  1. 59
    0
      pkgup

+ 59
- 0
pkgup View File

@@ -0,0 +1,59 @@
1
+#!/usr/bin/env bash
2
+
3
+has() {
4
+  local verbose=0
5
+  if [[ $1 = '-v' ]]; then
6
+    verbose=1
7
+    shift
8
+  fi
9
+  for c; do c="${c%% *}"
10
+    if ! command -v "$c" &> /dev/null; then
11
+      (( "$verbose" > 0 )) && err "$c not found"
12
+      return 1
13
+    fi
14
+  done
15
+}
16
+
17
+err() {
18
+  printf "\e[31m%s\e[0m\n" "$*" >&2
19
+}
20
+
21
+die() {
22
+  (( $# > 0 )) && err "$*"
23
+  exit 1
24
+}
25
+
26
+select_from() {
27
+  local cmd='command -v'
28
+  for a; do
29
+    case "$a" in
30
+      -c)
31
+        cmd="$2"
32
+        shift 2
33
+        ;;
34
+    esac
35
+  done
36
+  for c; do
37
+    if $cmd "${c%% *}" &> /dev/null; then
38
+      echo "$c"
39
+      return 0
40
+    fi
41
+  done
42
+  return 1
43
+}
44
+
45
+has -v fzf || die
46
+
47
+helper=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
48
+
49
+mapfile -t pkgs < <(
50
+  $helper -Qu --color=always |
51
+  fzf --ansi -e -m --inline-info --cycle --reverse --bind='Ctrl-A:toggle-all' |
52
+  awk '{print $3}'
53
+)
54
+
55
+count="${#pkgs[@]} package"
56
+(( ${#pkgs[@]} > 1 )) && count+='s'
57
+printf "upgrading %s: %s\n" "$count" "${pkgs[*]}"
58
+
59
+(( ${#pkgs[@]} > 0 )) && $helper -S "${pkgs[@]}"

Loading…
Cancel
Save