From 6a156c9bbd5176f85911632af1b497eccfac7edb Mon Sep 17 00:00:00 2001 From: cage Date: Wed, 20 Mar 2024 14:43:00 +0100 Subject: [PATCH] - added short options to bash complations. --- src/command-line.lisp | 57 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/command-line.lisp b/src/command-line.lisp index 78869d5..5545fb3 100644 --- a/src/command-line.lisp +++ b/src/command-line.lisp @@ -81,7 +81,7 @@ :long "gemini-gui-client-only") (:name :gemini-gui-server :description (_ "Start as gemini gui server only.") - :short +start-server-command-line+ + :short ,+start-server-command-line+ :long "gemini-gui-server-only") (:name :load-module :description (_ "Load a module.") @@ -143,28 +143,39 @@ (setf ,option-variable ,option-value)))) (defun complete () - (let ((options (mapcar (lambda (a) (text-utils:strcat "--" (getf a :long ""))) - (options))) - (words (text-utils:split-words (os-utils:getenv "COMP_WORDS"))) - (words-index (ignore-errors (parse-integer (os-utils:getenv "COMP_CWORD")))) - (command-line (os-utils:getenv "COMP_LINE"))) - (declare (ignore command-line)) - (when (and words - words-index) - (if (< words-index - (length words)) - (let* ((options (mapcar (lambda (a) (text-utils:strcat "--" (getf a :long ""))) - (options))) - (matched (remove-if-not (lambda (a) (cl-ppcre:scan (elt words words-index) - a)) - options))) - (if matched - (write-sequence (text-utils:join-with-strings matched " ") - *standard-output*) - (write-sequence (text-utils:join-with-strings options " ") - *standard-output*))) - (write-sequence (text-utils:join-with-strings options " ") - *standard-output*))))) + (flet ((write-shell-array (sequence) + (write-sequence (text-utils:join-with-strings sequence " ") + *standard-output*)) + (build-options (all-options switch-prefix key) + (remove-if (lambda (a) (string= a switch-prefix)) + (mapcar (lambda (a) (format nil + "~a~a" + switch-prefix + (getf a key ""))) + all-options)))) + (let* ((all-options (options)) + (long-options (build-options all-options "--" :long)) + (short-options (build-options all-options "-" :short)) + (options (nconc long-options short-options)) + (words (text-utils:split-words (os-utils:getenv "COMP_WORDS"))) + (words-index (ignore-errors (parse-integer (os-utils:getenv "COMP_CWORD")))) + (command-line (os-utils:getenv "COMP_LINE"))) + (declare (ignore command-line)) + (when (and words + words-index) + (if (< words-index + (length words)) + (let ((matched (sort (remove-if-not (lambda (a) + (cl-ppcre:scan (strcat "^" + (elt words words-index)) + a)) + options) + (lambda (a b) (< (length a) (length b)))))) + (if matched + (progn + (write-shell-array matched)) + (write-shell-array options))) + (write-shell-array options)))))) (defun manage-opts () (handler-bind ((opts:unknown-option #'exit-on-error)