-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsparu
executable file
·322 lines (300 loc) · 10.7 KB
/
lsparu
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
# ------------------------------------------------------------------
# Title: lsparu
# Created: 2021-10-19, version 0.0.1
# Copysomething (C?) 2021 Niklas Adam
#
# Description:
# a fuzzy paru lister that finds and selects
# pacman and aur packages for installation
#
# Dependencies:
# paru, fzf
# ------------------------------------------------------------------
#
# Email: [email protected]
# URL: https://niklasadam.oddodd.org
#
# ------------------------------------------------------------------
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
version=1.0.0
identity=lsparu # not used, you can simultaneously run as many lsparu's as you like
usage="usage: lsparu -sqrmfy {args} -hv"
display_help() {
echo
echo "╔════════════════════╗"
echo "║░ lsparu ░║"
echo "╚════════════════════╝"
echo
echo "$usage"
echo "path: $0 "
echo
echo " -s, -style select [(l|light)|(m|mono)(p|paper)]"
echo " -q, -query input starting search query"
echo " -r, -repository browse a specific repo [core|extra|community|aur]"
echo " -m, -margin set the margin 10|2,5|5,3,8|1,5,2,3"
echo " -h, -help show this help"
echo " -v, -version get lsparu version"
echo
echo " ctrl-space toggle package"
echo " ctrl-d deselect-all"
echo " ctrl-l clear-query"
echo " ctrl-p toggle-preview"
echo " ctrl-w toggle-preview-wrap"
echo " shift-up preview-up"
echo " shift-down preview-down"
echo " shift-left preview-page-up"
echo " shift-right preview-page-down"
echo " ctrl-s see package stats"
echo " ctrl-u list updatable packages"
echo " ctrl-n read the news"
echo " ctrl-g get info about installed packages"
echo " enter install package(s)"
echo " esc leave, do nothing"
echo " tab toggle package and move pointer down"
echo " shift-tab toggle package and move pointer up"
echo " ctrl-h list keybindings (help)"
echo
exit 0
}
# array declaration
declare -a repo
declare -a not_supported_repo
declare -a tmp_array
supported_repositories='core|extra|community|aur'
margin=2,3 # default margin
check_supported_repo() {
# get length of the array
num_repos_requested=${#repo[@]}
# check support
for (( i=1; i<${num_repos_requested}+1; i++ ));
do
if [[ ${repo[$i-1]} =~ ^($supported_repositories)$ ]]; then
echo "queried repo: ${repo[$i-1]}"
else
echo " ! ${repo[$i-1]} is not a supported repo"
not_supported_repo+=($(eval "echo \${repo[$i-1]}"))
fi
done
#echo "the not supported elements are: ${not_supported_repo[@]} "
# delete the array elements (repos) that are not supported
for element_for_deletion in ${not_supported_repo[@]}
do
repo=("${repo[@]/$element_for_deletion}") #delete the not supported element in question
done
# bash arrays are not mutable by design..
# rebuild the array to fill the gaps left after deletion
for i in "${!repo[@]}"; do
# if it is not empty fill tmp
if [ -n "${repo[i]}" ]; then
tmp_array+=("${repo[i]}")
#echo "tmp: ${tmp_array[@]}"
fi
done
# rebuild repo array
repo=("${tmp_array[@]}")
unset tmp_array # empty the tmp_array
# results
#echo "result: ${repo[@]}"
}
#unset -v repo
while getopts s:q:r:m:f:hv option
do
case "${option}" in
s | style) style=${OPTARG}
info_style="-s ${OPTARG}" # for lsparu-query
;;
q | query) query=${OPTARG}
;;
r | repository) repo=("$OPTARG")
# get all args input after -r . stop at new option
until [[ $(eval "echo \${$OPTIND}") =~ ^-.* ]] || [ -z $(eval "echo \${$OPTIND}") ]; do
repo+=($(eval "echo \${$OPTIND}"))
OPTIND=$((OPTIND + 1))
done
check_supported_repo
;;
m | margin) margin=${OPTARG}
info_margin="-m ${OPTARG}" # for lsparu-query
;;
h | help)
display_help
;;
v | version)
echo "lsparu v$version"
exit 0
;;
*)
echo $usage
exit 0
;;
esac
done
default_colors() {
header=#fabd2f
bg=#1d2021
bgp=#504945
fg=#fe8019
fgp=#fabd2f
previewbg=#1d2001
previewfg=#b8bb26
info=#83a598
border=#fb4934
spinner=#fe8019
hl=#83a598
hlp=#8ec07c
pointer=#fb4934
prompt=#fb4934
gutter=#3c3836
marker=#fb4934
}
light_colors() {
header=#fe5009
bg=#ebdbb2
bgp=#d5c4a1
fg=#000000
fgp=#504945
previewbg=#8ec07c
previewfg=#000000
info=#665c54
border=#d3869b
spinner=#fe8019
hl=#1102aa
hlp=#1102fb
pointer=#fe5009
prompt=#b8bb26
gutter=#8ec07c
marker=#1f92fb
}
mono_colors() {
header=#a1efe4
bg=#272822
bgp=#223aa2
fg=#a6e22e
fgp=#fc6633
previewbg=#125849
previewfg=#fc6633
info=#f5f4f1
border=#a1efe4
spinner=#f4bf75
hl=#66d9ef
hlp=#66d9af
pointer=#ae81ff
prompt=#f8a8f2
gutter=#383830
marker=#fc6633
}
paper_colors() {
header=#d7875f
bg=#1c1c1c
bgp=#000a58
#5f8787
fg=#5fafd7
fgp=#1ae00f
previewbg=#585858
previewfg=#ffaf00
info=#afd700
border=#af005f
spinner=#00afaf
hl=#d7af5f
hlp=#f9cf50
pointer=#af005f
prompt=#808080
gutter=#4c8787
marker=#af005f
}
# set colors
case $style in
light | l)
light_colors
;;
mono | m)
mono_colors
;;
paper | p)
paper_colors
;;
*)
default_colors
info_style="" # for lsparu-query
;;
esac
stats="paru -Ps | fzf --phony --reverse --no-bold --margin $margin% \
--header=$'╔════════════════════╗ \n║░ stats ░║\n╚════════════════════╝\n ' \
--pointer='▓' --prompt='' --border=sharp \
--bind 'enter:abort' \
--color='bg:'$bg,'bg+:'$bg,'border:'$border,'spinner:'$spinner \
--color='hl:'$hl,'fg:'$fg,'fg+:'$fg,'pointer:'$fg,'header:'$header \
--color='hl+:'$hlp,'marker:'$marker,'info:'$bg"
upgrades="paru -Qu | fzf --reverse --no-bold --margin $margin% \
--header=$'╔═════════════════════╗ \n║░ upgradable pkgs ░║\n╚═════════════════════╝\n\n' \
--pointer='▓' --prompt='~' --border=sharp \
--bind 'enter:abort' \
--color='bg:'$bg,'bg+:'$bg,'border:'$border,'spinner:'$spinner \
--color='hl:'$hl,'fg:'$fg,'fg+:'$fg,'pointer:'$fg,'header:'$header \
--color='hl+:'$hlp,'marker:'$marker,'info:'$bg"
news="paru -Pww | fold -s -w 70 | fzf --phony --reverse --no-bold --ansi --margin $margin% \
--header=$'╔════════════════════╗ \n║░ news ░║\n╚════════════════════╝\n ' \
--pointer='▓' --prompt='' --border=sharp \
--bind 'enter:abort' \
--color='bg:'$bg,'bg+:'$bg,'border:'$border,'spinner:'$spinner \
--color='hl:'$hl,'fg:'$fg,'fg+:'$fg,'pointer:'$fg,'header:'$header \
--color='hl+:'$hlp,'marker:'$marker,'info:'$bg"
keybindings="printf '%s\n%s' \
'ctrl-space toggle package' '' \
'ctrl-d deselect-all' '' \
'ctrl-l clear-query' '' \
'ctrl-p toggle-preview' '' \
'ctrl-w toggle-preview-wrap' '' \
'shift-up preview-up' '' \
'shift-down preview-down' '' \
'shift-left preview-page-up' '' \
'shift-right preview-page-down' '' \
'ctrl-s see package stats' '' \
'ctrl-u list updatable packages' '' \
'ctrl-n read the news' '' \
'ctrl-g get info about installed packages' '' \
'enter install package[s]' '' \
'esc leave, do nothing' '' \
'tab toggle package and move pointer down' '' \
'shift-tab toggle package and move pointer up' '' \
'ctrl-h [help] show keybindings'"
lsparu_help="$keybindings | fzf --phony --reverse --no-bold --margin $margin% \
--header=$'╔════════════════════╗ \n║░ keybindings ░║\n╚════════════════════╝\n ' \
--pointer='▓' --prompt='' --border=sharp \
--bind 'enter:abort' \
--color='bg:'$bg,'bg+:'$bg,'border:'$border,'spinner:'$spinner \
--color='hl:'$hl,'fg:'$fg,'fg+:'$fg,'pointer:'$fg,'header:'$header \
--color='hl+:'$hlp,'marker:'$marker,'info:'$bg"
# the fuzzy paru
paru -Sl ${repo[@]} | fzf --preview 'paru -Si {2} | tail -n +2' \
-q "$query" -e -m --reverse --margin $margin% \
--pointer='▓' --prompt='~ ' --marker='<>' \
--preview-window=right:60% --border=sharp \
--bind 'ctrl-w:toggle-preview-wrap' \
--bind 'ctrl-l:clear-query' \
--bind 'ctrl-d:deselect-all' \
--bind 'ctrl-space:toggle' \
--bind 'ctrl-p:toggle-preview' \
--bind 'shift-right:preview-page-down' \
--bind 'shift-left:preview-page-up' \
--bind 'ctrl-s:execute('"$stats"')' \
--bind 'ctrl-u:execute('"$upgrades"')' \
--bind 'ctrl-n:execute('"$news"')' \
--bind 'ctrl-g:execute('"source lsparu-query $info_style $info_margin"')' \
--bind 'ctrl-h:execute('"$lsparu_help"')' \
--header=$'╔════════════════════╗ \n║░ lsparu ░║\n╚════════════════════╝\n ' \
--color='bg:'$bg,'bg+:'$bgp,'info:'$info,'border:'$border,'spinner:'$spinner,'gutter:'$gutter \
--color='hl:'$hl,'fg:'$fg,'fg+:'$fgp,'pointer:'$pointer,'prompt:'$prompt,'header:'$header \
--color='hl+:'$hlp,'marker:'$marker,'preview-bg:'$previewbg,'preview-fg:'$previewfg \
| awk '{print $2}' | xargs -ro paru -S