gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master c02ae2c 02/62: Completion: feed options from `


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c02ae2c 02/62: Completion: feed options from `help`
Date: Thu, 13 May 2021 22:20:44 -0400 (EDT)

branch: master
commit c02ae2c7efb17def0091dd35847d76f86750c9a6
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Completion: feed options from `help`
    
    Until now, the completion options were fed from the `args.h` file of the
    corresponding program. With this commit, completions will be fed through
    the auto-generated `--help` option. This ensures that completion will be
    kept up-to-date in each release of each program.
---
 bin/cosmiccal/astcosmiccal-completion.bash | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/bin/cosmiccal/astcosmiccal-completion.bash 
b/bin/cosmiccal/astcosmiccal-completion.bash
index 8e81306..c7479da 100644
--- a/bin/cosmiccal/astcosmiccal-completion.bash
+++ b/bin/cosmiccal/astcosmiccal-completion.bash
@@ -6,20 +6,6 @@
 
 _astcosmiccal_completions(){
 
-    # PATH_TO_COMMAND_BIN, i.e. the directory which the astcosmiccal
-    # command sits in.
-    local PATH_TO_COMMAND_BIN=".";
-
-    # Use "args.h" file to filter out all valid options of the command and
-    # put them all in the variable "commandoptions".
-
-    local commandoptions=$(sed -n -E '/^\s+\"[a-z]+/p' \
-                               "$PATH_TO_COMMAND_BIN/args.h" | \
-                               # remove newline and space characters
-                               tr -d '\n" ' | \
-                               # replace commas with spaces
-                               tr ',' ' ');
-
     # Initialize the completion response with null
     COMPREPLY=();
 
@@ -29,13 +15,16 @@ _astcosmiccal_completions(){
     # Variable "prev" is the word just before the current word
     local prev="${COMP_WORDS[COMP_CWORD-1]}";
 
-    if [ $prev = "lineatz" ]; then
-        # Show options related to "lineatz"
+    if [ $prev = "--lineatz" ]; then
+        # Show all sub options in "lineatz"
         COMPREPLY=($(compgen -W "$(astcosmiccal --listlines | \
                            awk '!/^#/ {print $2}') " \
                            -- "$word"));
     else
-        COMPREPLY=($(compgen -W "$commandoptions" -- "$word"));
+        # Show all options in CosmicCalculator:
+        COMPREPLY=($(compgen -W "$(astcosmiccal --help | \
+                             awk 'match($0, /--[a-z]+/) {print substr($0, 
RSTART, RLENGTH)}') " \
+                             -- "$word"));
     fi;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]