5901f30b44fc5a3055e6b801d3d71af6d2359ee8

Author
WH-2099 <wh2099@outlook.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(archlinux): optimize `paclist` and `pacdisowned` (#11398)

Co-authored-by: ratijas <me@ratijas.tk>

Diff

 1diff --git a/plugins/archlinux/README.md b/plugins/archlinux/README.md
 2index fd772c61a995a0c8aca144087163c86315cf2a5a..5e015dbaa02325a5fc1faa29673bca874a0a41db 100644
 3--- a/plugins/archlinux/README.md
 4+++ b/plugins/archlinux/README.md
 5@@ -181,3 +181,4 @@ whether the package manager is installed, checked in the following order:
 6 - Ybalrid (Arthur Brainville) - ybalrid@ybalrid.info
 7 - Jeff M. Hubbard - jeffmhubbard@gmail.com
 8 - K. Harishankar(harishnkr) - hari2menon1234@gmail.com
 9+- WH-2099 - wh2099@outlook.com
10diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh
11index da170f488fade8c4b703c6415645aa1616cbc48b..796ff7adf122f01c8ef74b8050664c5c4d965c3f 100644
12--- a/plugins/archlinux/archlinux.plugin.zsh
13+++ b/plugins/archlinux/archlinux.plugin.zsh
14@@ -25,27 +25,28 @@ alias pacown='pacman -Qo'
15 alias pacupd="sudo pacman -Sy"
16 
17 function paclist() {
18-  # Based on https://bbs.archlinux.org/viewtopic.php?id=93683
19-  pacman -Qqe | \
20-    xargs -I '{}' \
21-      expac "${bold_color}% 20n ${fg_no_bold[white]}%d${reset_color}" '{}'
22+  local pkgs=$(LC_ALL=C pacman -Qqe)
23+  for pkg in ${(f)pkgs}; do
24+      pacman -Qs --color=auto "^${pkg}\$" || break
25+  done
26 }
27 
28 function pacdisowned() {
29-  local tmp db fs
30-  tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
31-  db=$tmp/db
32-  fs=$tmp/fs
33+  local tmp_dir db fs
34+  tmp_dir=$(mktemp --directory)
35+  db=$tmp_dir/db
36+  fs=$tmp_dir/fs
37 
38-  mkdir "$tmp"
39-  trap 'rm -rf "$tmp"' EXIT
40+  trap "rm -rf $tmp_dir" EXIT
41 
42   pacman -Qlq | sort -u > "$db"
43 
44-  find /bin /etc /lib /sbin /usr ! -name lost+found \
45+  find /etc /usr ! -name lost+found \
46     \( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
47 
48   comm -23 "$fs" "$db"
49+
50+  rm -rf $tmp_dir
51 }
52 
53 alias pacmanallkeys='sudo pacman-key --refresh-keys'