1. Removed unnecessary punctuation to help with readability
2. Loop over RES elements directly instead of indexing
3. Declare COMPGEN_OPTS only once vs redeclaring on each iteration
(cherry picked from commit 02fc85a3c2):
1. Use $() command substitution instead of legacy `` style
2. Properly quote COMPGEN_OPTS
3. Use readarray instead of relying on word splitting
(cherry picked from commit 21ae7723c0):
A few global variables were being created unecessarily still. This makes
sure that users shell environments are not polluted by extra variables
and that the completion doesn't modify unrelated variables
(cherry picked from commit 9047dabfaf):
Currently flatpak's bash completion is a bit broken. It shows all files
with the appropriate extension (.flatpak or .flatpakref) rather than
just the ones starting with the characters you've already typed. So this
commit fixes that behavior by using the -X compgen option rather than
-G. For example, here's the old behavior:
$ flatpak install e<TAB>
bijiben.flatpak eos eos-runtimes
builder.flatpak eos-apps eos-sdk
and here's the new behavior:
$ flatpak install e<TAB>
eos eos-apps eos-runtimes eos-sdk
$ flatpak install b<TAB>
bijiben.flatpak builder.flatpak
Closes: #1645
Approved by: alexlarsson
Many flatpak commands only work on *.flatpak or *.flatpakref files, so
the bash auto completion showing every file is distracting and
unnecessary. This commit makes flatpak only show relevant files when
possible by using the "-G globpattern" compgen option.
This allows to restrict the access that the app gets out of
the sandbox. We allow an access if the app requests it (in its
metadata) and the user doesn't forbid it (with this option).