zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] modutils completion: Fix FHS assumption
@ 2020-06-01 17:05 doron.behar
  2020-06-01 17:56 ` Doron Behar
  0 siblings, 1 reply; 2+ messages in thread
From: doron.behar @ 2020-06-01 17:05 UTC (permalink / raw)
  To: zsh-workers

From: Doron Behar <doron.behar@gmail.com>

---
 Completion/Linux/Command/_modutils | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
index ff6844f41..a0ed7b210 100644
--- a/Completion/Linux/Command/_modutils
+++ b/Completion/Linux/Command/_modutils
@@ -12,7 +12,18 @@ _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=(
+    # NixOS & possibly Guix
+    /run/booted-system/kernel-modules/lib/modules
+    # Mostly every other distro
+    /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"
+    fi
+  done
 
   local update_policy
   zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
@@ -108,6 +119,9 @@ _modutils() {
     all-modules)
       local kver=${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) )
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] modutils completion: Fix FHS assumption
  2020-06-01 17:05 [PATCH] modutils completion: Fix FHS assumption doron.behar
@ 2020-06-01 17:56 ` Doron Behar
  0 siblings, 0 replies; 2+ messages in thread
From: Doron Behar @ 2020-06-01 17:56 UTC (permalink / raw)
  To: zsh-workers

This Patch has been previously discussed at
https://gitlab.com/zsh-org/zsh/-/merge_requests/15 but Daniel Shahaf and
I wish to get more feedback as to whether this brakes and `modutils`
related command for anyone.

Basically, the $modules_dir is set just like before, but if
`/run/booted-system/kernel-modules/lib/modules` exists, it's being used
instead of the default `/lib/modules` - the 1st directory is the
directory used on NixOS and Guix.

This patch fixes an ugly error for NixOS and Guix utils which goes like
this:


    $ modinfo <tab> _modutils:102: no such file or directory:
    /lib/modules/5.6.15/modules.alias


On Mon, Jun 01, 2020 at 08:05:19PM +0300, doron.behar@gmail.com wrote:
> From: Doron Behar <doron.behar@gmail.com>
> 
> ---
>  Completion/Linux/Command/_modutils | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils
> index ff6844f41..a0ed7b210 100644
> --- a/Completion/Linux/Command/_modutils
> +++ b/Completion/Linux/Command/_modutils
> @@ -12,7 +12,18 @@ _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=(
> +    # NixOS & possibly Guix
> +    /run/booted-system/kernel-modules/lib/modules
> +    # Mostly every other distro
> +    /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"
> +    fi
> +  done
>  
>    local update_policy
>    zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
> @@ -108,6 +119,9 @@ _modutils() {
>      all-modules)
>        local kver=${opt_args[(i)(-S|-k|--set-version)]:-$(uname -r)}
>  
> +      if [[ -z "$modules_dir" ]]; then
> +        return
> +      fi

I _think_ this addition will also gracefully catch the edge case of a
modules directory not found at all.

>        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) )
> -- 
> 2.26.2
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-03 16:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 17:05 [PATCH] modutils completion: Fix FHS assumption doron.behar
2020-06-01 17:56 ` Doron Behar

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).