diff options
author | Doron Behar <doron.behar@gmail.com> | 2020-05-31 14:51:33 +0300 |
---|---|---|
committer | Oliver Kiddle <okiddle@yahoo.co.uk> | 2020-07-08 18:07:39 +0200 |
commit | 02f62e5d21e09d4936e18147119b1f0c85b93d79 (patch) | |
tree | a078dada739f67b5ab0bf5704716cd1ea1eedf9f | |
parent | 57a735f6b9282024919eefcc6e59b3c4e22536d2 (diff) | |
download | zsh-02f62e5d21e09d4936e18147119b1f0c85b93d79.tar.gz zsh-02f62e5d21e09d4936e18147119b1f0c85b93d79.tar.xz zsh-02f62e5d21e09d4936e18147119b1f0c85b93d79.zip |
gitlab !15: modutils completion: Fix FHS assumption
Remove calls to programs from /sbin/ with _call_program and to avoid the system complies to the FHS. Support modules completion for NixOS and Guix which store their kernel modules not at /lib/modules.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Completion/Linux/Command/_modutils | 23 |
2 files changed, 23 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index 9ea9a1335..60333be4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-07-08 Oliver Kiddle <okiddle@yahoo.co.uk> + * gitlab !15: Doron Behar: Completion/Linux/Command/_modutils: + Fix FHS assumption + * 46201 (tweaked per Daniel): Etc/completion-style-guide: add guidelines for caching and use of imperative mood in descriptions diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils index cada38a16..c62c6e7b6 100644 --- a/Completion/Linux/Command/_modutils +++ b/Completion/Linux/Command/_modutils @@ -12,7 +12,19 @@ _modules_caching_policy() _modutils() { local curcontext="$curcontext" expl state line modules modaliases ign args ret=1 local -A opt_args - local -r modules_dir=/lib/modules + local -a possible_modules_dirs=( + # Mostly every other distro + /lib/modules + # NixOS & possibly Guix + /run/booted-system/kernel-modules/lib/modules + ) + local modules_dir tested_modules_dir + for tested_modules_dir in "${possible_modules_dirs[@]}"; do + if [[ -d "$tested_modules_dir" ]]; then + modules_dir="$tested_modules_dir" + break + fi + done local update_policy zstyle -s ":completion:*:*:$service:*" cache-policy update_policy @@ -93,8 +105,10 @@ _modutils() { loaded-modules|loadable-modules) if [[ -r /proc/modules ]]; then loaded_modules=(${${(f)"$(</proc/modules)"}%% *}) + # For compatibilty with old systems. Kernels nowadays provide + # `/proc/modules` which is more reliable and faster for us. elif [[ -x /sbin/lsmod ]]; then - loaded_modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *}) + loaded_modules=(${${(f)"$(_call_program loaded-modules /sbin/lsmod)"}[2,-1]%% *}) else return 1 fi @@ -108,6 +122,9 @@ _modutils() { all-modules) local kver=${(v)opt_args[(i)(-S|-k|--set-version)]:-$(uname -r)} + if [[ -z "$modules_dir" ]]; then + return + fi if _cache_invalid modules-$kver || ! _retrieve_cache modules-$kver; then modules=( $modules_dir/$kver/(*~(source|build))/**/*.(o|ko|ko.gz|ko.xz)(.:t:r:r) ) @@ -137,7 +154,7 @@ _modutils() { _message -e value 'parameter value' else local params - params=( ${${(M)${(f)"$(_call_program module-parameters /sbin/modinfo "$words[2]" 2>/dev/null)"}:#parm:*}##parm:[[:space:]]##} ) + params=( ${${(M)${(f)"$(_call_program module-parameters modinfo "$words[2]" 2>/dev/null)"}:#parm:*}##parm:[[:space:]]##} ) compset -S '=*' if (( $#params )); then _values -S = -w 'module parameter' \ |