unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Bash autocompletion for guild.
@ 2019-06-05 18:27 Hugo Hörnquist
  0 siblings, 0 replies; only message in thread
From: Hugo Hörnquist @ 2019-06-05 18:27 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

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

[-- Attachment #2: 0001-Add-bash_completion-for-guild.patch --]
[-- Type: text/plain, Size: 1612 bytes --]

From 25d545e25833e7c174bed8873f24ea525db0fc1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@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


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

only message in thread, other threads:[~2019-06-05 18:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 18:27 Bash autocompletion for guild Hugo Hörnquist

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 read-only IMAP folder(s) and NNTP newsgroup(s).