zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] sysctl: support completion with the dot delimiter on linux
@ 2024-10-14 15:31 Eric Cook
  0 siblings, 0 replies; only message in thread
From: Eric Cook @ 2024-10-14 15:31 UTC (permalink / raw)
  To: zsh-workers

This was a request from irc. historically zsh did completion using / as the
delimiter (via _files) which while supported, kinda foreign to users of other
OSes and how sysctl examples are commonly shown online.

As is the patch changes the delimiter used to `.' but will still perform
completion should `/' be used, along with a style to get the old behavior
by default. that style will be ignored should the user attempt completion
with the other delimiter.

If changing the delimiter to `.' is undesired, i can swap them around.

(the globbing of /proc/sys/ was deemed faster than using `sysctl -aN' FWIW)

---
diff --git a/Completion/Unix/Command/_sysctl b/Completion/Unix/Command/_sysctl
index 442953c4d..09995c98e 100644
--- a/Completion/Unix/Command/_sysctl
+++ b/Completion/Unix/Command/_sysctl
@@ -23,10 +23,18 @@ case $OSTYPE in
      else
        args=( ${args:#((#s)|*\))(\*|)--*} )     # remove long options
      fi
+    local delimiter=.
+    sysctlvars=( /proc/sys/**/*(.e*'REPLY=${REPLY#/proc/sys/}'*) )
+    if zstyle -t ":completion:${curcontext}:argument-rest" delimiter / || (( ${words[CURRENT][(Ie)/]} )); then
+      delimiter=/
+    else
+      sysctlvars=(${sysctlvars//\//.})
+    fi
+
      _arguments -S -A "-*" : $args \
        '(- :)'{-h,--help}'[display help text and exit]' \
        '(- :)'{-V,--version}'[display version info and exit]' \
-      '*:sysctl variable:_files -W /proc/sys'
+      "*:sysctl variable:_multi_parts -i -S = -q $delimiter sysctlvars"
    ;;
    freebsd<14->.*)
      args+=(


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-14 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-14 15:31 [PATCH] sysctl: support completion with the dot delimiter on linux Eric Cook

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