Skip to content

Fix find_desktop_file and minor bug fixes.#11

Open
jastintime wants to merge 1 commit into
BachoSeven:masterfrom
jastintime:bugfix
Open

Fix find_desktop_file and minor bug fixes.#11
jastintime wants to merge 1 commit into
BachoSeven:masterfrom
jastintime:bugfix

Conversation

@jastintime
Copy link
Copy Markdown

find_desktop_file_by was previously using

[[ -z "$HOME/.local/share/applications" ]] &&

This is incorrect, the string in this test will never be empty instead what we want to do is check if the directory does not exist this can be achived with

[[ ! -d "$HOME/..." ]] &&

https://www.shellcheck.net/wiki/SC2157

protocol is changed from =file to "file" to make it obvious we are setting it to the string not the program
https://www.shellcheck.net/wiki/SC2209

- if [[ -n "$(echo "$w" | grep '^$')" ]]; then
+ if echo "$w" | grep -q '^$';then

we change from [[ -n ]] to grep -q to quit early if we don't match and to make it a bit cleaner.

- program="$(echo "$w" | sed 's/^$//')"
- app[$i]
+ program="${w#$}"
+ app[i]
https://www.shellcheck.net/wiki/SC2001
https://www.shellcheck.net/wiki/SC2004

A little less overhead without an external call, also a bit easier to read

Remaining changes were simply explictly passing in a function argument and double quoting to prevent globbing.

Note

Shellcheck still complains about https://www.shellcheck.net/wiki/SC2207

Fixing that is probably a good idea.

find_desktop_file_by was previously using
> [[ -z "$HOME/.local/share/applications" ]] &&
This is incorrect, the string in this test will never be empty
instead what we want to do is check if the directory does not exist
this can be achived with
> [[ ! -d "$HOME/..." ]] &&
https://www.shellcheck.net/wiki/SC2157

protocol is changed from =file to "file" to make it obvious
we are setting it to the string not the program
https://www.shellcheck.net/wiki/SC2209

> -  if [[ -n "$(echo "$w" | grep '^\$')" ]]; then
> + if echo "$w" | grep -q '^\$';then

we change from [[ -n ]] to grep -q to quit early if we don't
match and to make it a bit cleaner.

> - program="$(echo "$w" | sed 's/^\$//')"
> - app[$i]
> + program="${w#\$}"
> + app[i]
https://www.shellcheck.net/wiki/SC2001
https://www.shellcheck.net/wiki/SC2004

A little less overhead without an external call, also a bit easier to read

Remaining changes were simply explictly passing in a function argument
and double quoting to prevent globbing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant