Browse Source

added pkgm script

DanielFGray 2 years ago
parent
commit
88f7320d46
1 changed files with 47 additions and 0 deletions
  1. 47
    0
      pkgrm

+ 47
- 0
pkgrm View File

@@ -0,0 +1,47 @@
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
+has -v fzf || die
27
+
28
+fzf() {
29
+  command fzf --ansi -e --multi --no-hscroll --inline-info --cycle --reverse --bind='Ctrl-a:toggle-all' "$@"
30
+}
31
+
32
+if (( $# == 0 )); then
33
+package_list=$(pacman -Qs --color=always |
34
+  gawk '{
35
+    getline descr;
36
+    sub(/ */, "", descr);
37
+    repo = gensub(/\/.*/, "", 1);
38
+    name = gensub(/.*\//, "", 1, $1);
39
+    info = gensub(/[^ ]* /, "", 1);
40
+    print name, info, descr;
41
+  }')
42
+
43
+  mapfile -t pkgs < <(fzf -q '!^lib ' <<< "$package_list" | cut -d' ' -f1)
44
+  (( ${#pkgs[@]} > 0 )) && sudo pacman -Rcusn "${pkgs[@]}"
45
+else
46
+  sudo pacman -Rcusn "$@"
47
+fi

Loading…
Cancel
Save