fix(service,{invoke,update}-rc.d): fix regressions and refactor - #1653
Merged
Conversation
This is a fix for a regression I introduced in commit da26178 (2023-08-13) with a *too* early return. Even when `_comp_sysvdirs` returns no service directories, the `services` array had gotten additional completions from the results of `systemctl`. The conditional for the result of `_comp_sysvdirs` should only apply to the completion generation based on the `sysvdirs` array.
"_comp_compgen_services" (bash_completion) and "{invoke,update}-rc.d"
have similar logics to generate the service names based on the
directory structures for SysV init services. This patch provides a
single function "_comp_compgen_sysv_services" for the common logic.
There have been some differences in the excluded filenames between
"_comp_compgen_services" and "{invoke,update}-rc.d":
* The function "_comp_compgen_services" exclude the file "functions",
which contains utilities that are used by other service scripts.
The completions for "{invoke,update}-rc.d" exclude "*.sh" and also
the files starting with "README*". In the new generator
"_comp_compgen_sysv_services", we exclude all "*.sh", "functions",
and "README*".
* Another difference is the extraction of the SysV directory. The
completions for "{invoke,update}-rc.d" only checked /etc/rc.d/init.d
and /etc/init.d, but "_comp_compgen_services" based on
"_comp_sysvdirs" checked also /etc/slackware-version when neither
/etc/rc.d/init.d nor /etc/init.d is found. In the new generator, we
use "_comp_sysvdirs" to identify a SysV service directory.
We can also use "_comp_sysvdirs" in identifying the service script for the completion of an action name.
This is a regression by Ref. [1]. In Ref. [1], I have replaced the combination of "_comp_expand_glob" and "_comp_compgen -- -W" with "_comp_compgen -C -- -f". However, I realized that this strategy would cause generation of the filenames in subdirectories when $cur contains "/" [2]. To avoid this, one can exclude candidates containing a slash by -X '*/*'. [1] scop#1553 [2] scop#1639 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm sorry, I noticed regressions I introduced in #1035 and #1553. This PR contains the fixes and related refactorings.