zsh-workers
 help / color / mirror / code / Atom feed
From: doron.behar@gmail.com
To: zsh-workers@zsh.org
Subject: [PATCH] modutils completion: Fix FHS assumption
Date: Mon,  1 Jun 2020 20:05:19 +0300	[thread overview]
Message-ID: <20200601170519.7665-1-doron.behar@gmail.com> (raw)

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


             reply	other threads:[~2020-06-01 17:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-01 17:05 doron.behar [this message]
2020-06-01 17:56 ` Doron Behar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200601170519.7665-1-doron.behar@gmail.com \
    --to=doron.behar@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).