Browse Source

pkgrm can --sort by size

DanielFGray 2 years ago
parent
commit
3d8e351174
1 changed files with 17 additions and 15 deletions
  1. 17
    15
      pkgrm

+ 17
- 15
pkgrm View File

@@ -1,5 +1,7 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+declare by_size
4
+
3 5
 has() {
4 6
   local verbose=0
5 7
   if [[ $1 = '-v' ]]; then
@@ -26,22 +28,22 @@ die() {
26 28
 has -v fzf || die
27 29
 
28 30
 fzf() {
29
-  command fzf --ansi -e --multi --no-hscroll --inline-info --cycle --reverse --bind='Ctrl-a:toggle-all' "$@"
31
+  command fzf -e --multi --no-hscroll --inline-info --cycle --bind='Ctrl-a:toggle-all' "$@"
30 32
 }
31 33
 
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
34
+case $1 in
35
+  -s|--size) by_size=1; shift;
36
+esac
37
+
38
+if (( $# > 0 )); then
46 39
   sudo pacman -Rcusn "$@"
40
+  exit
47 41
 fi
42
+
43
+if (( by_size )); then
44
+  mapfile -t pkgs < <(expac -H M '%m\t%n' | sort -hr | fzf --preview='pacman -Si {3}' -q '!^lib ' | cut -f2)
45
+else
46
+  mapfile -t pkgs < <(expac '%n' | fzf --preview='pacman -Si {1}' -q '!^lib ' | cut -d' ' -f1)
47
+fi
48
+
49
+(( ${#pkgs[@]} > 0 )) && sudo pacman -Rcusn "${pkgs[@]}"

Loading…
Cancel
Save