-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflatpak-rm
executable file
·74 lines (69 loc) · 1.32 KB
/
flatpak-rm
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
#!/usr/bin/env bash
tab=$'\t'
fzf_args=(
'--exact'
'--multi'
"--delimiter=${tab}"
'--with-nth=1..2'
'--preview=flatpak info {2}//{4}'
'--preview-label=Flatpak Info'
'--preview-window=up'
)
pkgs=$(flatpak list)
help_msg() {
cat <<EOF
usage: flatpak-rm [-h] [-a | -r] [QUERY]
Interactively remove flatpaks with fzf.
Command-line Flags:
-h --help Show this message
-a --app Filter only applications
-r --runtime Filter only runtimes
EOF
}
declare -a query
# Parse command arguments
while [ -n "$1" ]; do
case "$1" in
-h | --help)
help_msg
exit 0
;;
-a | --app)
pkgs=$(flatpak list --app)
;;
-r | --runtime)
pkgs=$(flatpak list --runtime)
;;
-*)
printf 'Unknown flag: %s\n' "$1" >&2
help_msg >&2
exit 1
;;
*)
query+=("$1")
;;
esac
shift
done
mapfile -t ids < <(fzf "${fzf_args[@]}" --query="${query[*]}" <<<"$pkgs" | cut -d "$tab" -f 2)
if [[ -z ${ids[*]} ]]; then
echo "No files selected."
exit 0
else
echo "Uninstalling: ${ids[*]}"
while :; do
read -r -n 1 -p 'Continue? [Y/n]: ' ans
echo
case "$ans" in
n | N)
echo "User cancelled operation."
exit 0
;;
y | Y | '')
flatpak uninstall --delete-data --noninteractive -- "${ids[@]}"
exit "$?"
;;
*) continue ;;
esac
done
fi