aboutsummarylogtreecommitdiffstats
path: root/pacfzf
blob: 1a2bb339c0f2b5e4f6006cccdcc1926398839705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# pacfzf — fzf-based interactive package manager for Arch Linux
# Usage: pacfzf <command> [options]

VERSION="0.3.0"

# ── config ─────────────────────────────────────────────────────────────────────
AUR_QUERY_HELPER="yay"
AUR_INSTALL_HELPER="paru"

CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/pacfzf/config"
[[ -f $CONFIG_FILE ]] && source "$CONFIG_FILE"

_usage() {
cat <<EOF
pacfzf $VERSION — fzf-based interactive package manager for Arch Linux

Usage:
  pacfzf <command>

Commands:
  install         Browse and install packages from official repositories
  remove          Browse and remove installed packages from official repositories
  aur-install     Browse and install packages from the AUR
  aur-remove      Browse and remove installed AUR/foreign packages
  info            Browse installed packages and view package details
  history         Browse the pacman transaction log (most recent first)

Options:
  -h, --help      Show this help message
  -V, --version   Show version information

Key bindings (all commands):
  TAB             Multi-select a package
  ENTER           Confirm selection and proceed
  ESC             Cancel
  ALT-P           Toggle preview pane
  ALT-B           Toggle PKGBUILD view (aur-install, aur-remove only)
  ALT-F           Toggle installed files view (info only)
  ALT-D / ALT-U   Scroll preview down/up (half page)
  ALT-J / ALT-K   Scroll preview line by line

Configuration:
  ~/.config/pacfzf/config   Shell config file sourced at startup
  AUR_QUERY_HELPER          AUR helper for listing/previews (default: yay)
  AUR_INSTALL_HELPER        AUR helper for install/remove   (default: paru)

Examples:
  pacfzf install
  pacfzf remove
  pacfzf aur-install
  pacfzf aur-remove
  pacfzf info
  pacfzf history

See pacfzf(1) for full documentation.
EOF
}

cmd_install() {
fzf_args=(
--multi
--prompt 'Install > '
--header 'TAB: multi-select  ENTER: install  ESC: cancel  ALT-P: toggle preview'
--preview 'pacman -Sii {1}'
--preview-label ' Package Info '
--preview-label-pos 'bottom'
--preview-window 'down:65%:wrap'
--bind 'alt-p:toggle-preview'
--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
--bind 'alt-k:preview-up,alt-j:preview-down'
--color 'pointer:green,marker:green,header:italic'
)

pkg_names=$(pacman -Slq | fzf "${fzf_args[@]}")

if [[ -n $pkg_names ]]; then
echo "$pkg_names" | tr '\n' ' ' | xargs sudo pacman -S --noconfirm
fi
}

cmd_remove() {
fzf_args=(
--multi
--prompt 'Remove > '
--header 'TAB: multi-select  ENTER: remove  ESC: cancel  ALT-P: toggle preview'
--preview 'pacman -Qi {1}'
--preview-label ' Package Info '
--preview-label-pos 'bottom'
--preview-window 'down:65%:wrap'
--bind 'alt-p:toggle-preview'
--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
--bind 'alt-k:preview-up,alt-j:preview-down'
--color 'pointer:red,marker:red,header:italic'
)

pkg_names=$(pacman -Qqn | fzf "${fzf_args[@]}")

if [[ -n $pkg_names ]]; then
echo "$pkg_names" | tr '\n' ' ' | xargs sudo pacman -Rns --noconfirm
fi
}

cmd_aur_install() {
fzf_args=(
--multi
--prompt 'AUR Install > '
--header 'TAB: multi-select  ENTER: install  ESC: cancel  ALT-P: info  ALT-B: PKGBUILD'
--preview "$AUR_QUERY_HELPER -Siia {1}"
--preview-label ' AUR Package Info '
--preview-label-pos 'bottom'
--preview-window 'down:65%:wrap'
--bind 'alt-p:toggle-preview'
--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
--bind 'alt-k:preview-up,alt-j:preview-down'
--bind "alt-b:change-preview:$AUR_QUERY_HELPER -Gpa {1} | tail -n +5"
--bind 'alt-b:+change-preview-label: PKGBUILD '
--bind "alt-p:change-preview:$AUR_QUERY_HELPER -Siia {1}"
--bind 'alt-p:+change-preview-label: AUR Package Info '
--color 'pointer:green,marker:green,header:italic'
)

pkg_names=$($AUR_QUERY_HELPER -Slqa | fzf "${fzf_args[@]}")

if [[ -n $pkg_names ]]; then
echo "$pkg_names" | tr '\n' ' ' | xargs $AUR_INSTALL_HELPER -S --noconfirm
fi
}

cmd_aur_remove() {
fzf_args=(
--multi
--prompt 'AUR Remove > '
--header 'TAB: multi-select  ENTER: remove  ESC: cancel  ALT-P: info  ALT-B: PKGBUILD'
--preview "$AUR_QUERY_HELPER -Qi {1}"
--preview-label ' Package Info '
--preview-label-pos 'bottom'
--preview-window 'down:65%:wrap'
--bind 'alt-p:toggle-preview'
--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
--bind 'alt-k:preview-up,alt-j:preview-down'
--bind "alt-b:change-preview:$AUR_QUERY_HELPER -Gpa {1} | tail -n +5"
--bind 'alt-b:+change-preview-label: PKGBUILD '
--bind "alt-p:change-preview:$AUR_QUERY_HELPER -Qi {1}"
--bind 'alt-p:+change-preview-label: Package Info '
--color 'pointer:red,marker:red,header:italic'
)

pkg_names=$($AUR_QUERY_HELPER -Qqm | fzf "${fzf_args[@]}")

if [[ -n $pkg_names ]]; then
echo "$pkg_names" | tr '\n' ' ' | xargs $AUR_INSTALL_HELPER -Rns --noconfirm
fi
}

cmd_info() {
	fzf_args=(
		--prompt 'Info > '
		--header 'ALT-F: files  ESC: cancel  ALT-P: toggle preview'
		--preview 'pacman -Qi {1}'
		--preview-label ' Package Info '
		--preview-label-pos 'bottom'
		--preview-window 'down:65%:wrap'
		--bind 'alt-p:toggle-preview'
		--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
		--bind 'alt-k:preview-up,alt-j:preview-down'
		--bind 'alt-f:change-preview:pacman -Ql {1}'
		--bind 'alt-f:+change-preview-label: Installed Files '
		--bind 'alt-p:change-preview:pacman -Qi {1}'
		--bind 'alt-p:+change-preview-label: Package Info '
		--color 'pointer:cyan,marker:cyan,header:italic'
	)

	pacman -Qq | fzf "${fzf_args[@]}" > /dev/null
}

cmd_history() {
	fzf_args=(
		--prompt 'History > '
		--header 'Filter by typing  ESC: cancel  ALT-P: toggle preview'
		--preview 'echo {}'
		--preview-label ' Entry Detail '
		--preview-label-pos 'bottom'
		--preview-window 'down:25%:wrap'
		--bind 'alt-p:toggle-preview'
		--bind 'alt-d:preview-half-page-down,alt-u:preview-half-page-up'
		--bind 'alt-k:preview-up,alt-j:preview-down'
		--color 'pointer:yellow,marker:yellow,header:italic'
		--no-multi
	)

	grep '\[ALPM\] \(installed\|removed\|upgraded\)' /var/log/pacman.log \
		| sed 's/\[ALPM\] //' \
		| tac \
		| fzf "${fzf_args[@]}" > /dev/null
}

# ── entry point ────────────────────────────────────────────────────────────────

case "${1:-}" in
install)       cmd_install ;;
remove)        cmd_remove ;;
aur-install)   cmd_aur_install ;;
aur-remove)    cmd_aur_remove ;;
info)          cmd_info ;;
history)       cmd_history ;;
-h|--help)     _usage ;;
-V|--version)  echo "pacfzf $VERSION" ;;
"")
echo "pacfzf: no command given. See 'pacfzf --help'" >&2
exit 1
;;
*)
echo "pacfzf: unknown command '$1'. See 'pacfzf --help'" >&2
exit 1
;;
esac