Hi!

I added basic bash autocompletion for guild commands. Unfortunately
it's only for the first word, since flags for the individual commands
aren't given in on a standardized form.

-- 
hugo
>From 25d545e25833e7c174bed8873f24ea525db0fc1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <h...@hornquist.se>
Date: Wed, 5 Jun 2019 17:14:16 +0200
Subject: [PATCH] Add bash_completion for guild.

---
 bash_completion         | 5 +++++
 module/scripts/help.scm | 9 +++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 bash_completion

diff --git a/bash_completion b/bash_completion
new file mode 100644
index 000000000..a8e3361bc
--- /dev/null
+++ b/bash_completion
@@ -0,0 +1,5 @@
+_guild() {
+       COMPREPLY=( $(guild help --complete $2)  )
+}
+
+complete -F _guild -f guild
diff --git a/module/scripts/help.scm b/module/scripts/help.scm
index 34400db3a..b8d544e8b 100644
--- a/module/scripts/help.scm
+++ b/module/scripts/help.scm
@@ -165,6 +165,10 @@ For complete documentation, run: info '(guile)Using Guile 
Tools'
     (format #t "No documentation found for command \"~a\".\n"
             (module-command-name mod)))))
 
+(define (completions prefix)
+  (filter (lambda (s) (string-prefix? prefix s))
+          (find-submodules '(scripts))))
+
 (define %mod (current-module))
 (define (main . args)
   (cond
@@ -183,6 +187,11 @@ For complete documentation, run: info '(guile)Using Guile 
Tools'
        (else
         (format #t "No command named \"~a\".\n" name)
         (exit 1)))))
+   ((equal? (car args) "--complete")
+    (unless (null? (cdr args))
+      (for-each (lambda (completion)
+                  (display completion) (display " "))
+                (completions (cadr args)))))
    (else
     (show-help %mod (current-error-port))
     (exit 1))))
-- 
2.21.0

Reply via email to