Skip to content

Commit

Permalink
bash-completion: Do not use ls in completion
Browse files Browse the repository at this point in the history
Users might set aliases for ls breaking the bash completion:

```
alias ls='ls -N --color=yes --time-style=long-iso'
apport-bug <tab>
```

Shellcheck also complains about it:

```
shellcheck -S error -s bash data/bash-completion/{apport-bug,apport-collect,apport-unpack}

In data/bash-completion/apport-bug line 8:
        for FILE in $(ls /usr/share/apport/symptoms); do
                    ^-- SC2045 (error): Iterating over ls output is fragile. Use globs.

For more information:
  https://www.shellcheck.net/wiki/SC2045 -- Iterating over ls output is fragi...
```

Ubuntu-Bug: https://launchpad.net/bugs/1850804
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
  • Loading branch information
bdrung authored and schopin-pro committed Oct 17, 2023
1 parent 5b2ee88 commit 1f4a039
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions data/bash-completion/apport-bug
Expand Up @@ -3,17 +3,16 @@
# get available symptoms
_apport_symptoms ()
{
local syms
if [ -r /usr/share/apport/symptoms ]; then
for FILE in $(ls /usr/share/apport/symptoms); do
# hide utility files and symptoms that don't have a run() function
if [[ ! "$FILE" =~ ^_.* && -n $(egrep "^def run\s*\(.*\):" /usr/share/apport/symptoms/$FILE) ]]; then
syms="$syms ${FILE%.py}"
fi
done
fi
echo $syms

local filename path symptoms
for path in /usr/share/apport/symptoms/*; do
[[ -e "$path" ]] || continue
filename="${path##*/}"
# hide utility files and symptoms that don't have a run() function
[[ ! "$filename" =~ ^_.* ]] || continue
grep -Eq "^def run\s*\(.*\):" "$path" || continue
symptoms+=("${filename%.py}")
done
echo "${symptoms[*]}"
}

# completion when used without parameters
Expand Down

0 comments on commit 1f4a039

Please sign in to comment.