mirror of
https://codeberg.org/cage/tinmop/
synced 2025-02-18 08:20:35 +01:00
- added short options to bash complations.
This commit is contained in:
parent
fc31ba5ac7
commit
6a156c9bbd
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user