gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b5c4f29 27/62: Table: Completion, add options,


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b5c4f29 27/62: Table: Completion, add options, improve get name
Date: Thu, 13 May 2021 22:20:49 -0400 (EDT)

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

    Table: Completion, add options, improve get name
    
    Until now, the '_gnuastro_autocomplete_get_fits_name' function echoed
    the first fits file the user specified. This breaks the behavior for
    options such as '--catcolumns' because there might be several fits files
    on the command line.
    
    Nevertheless, everytime the user asks for the column names that belongs
    to the last fits file specified. Hence, the function will iterate
    through all words in the commandline, check them one by one and store
    them as a fits file if the name is valid, and then continue the loop
    until the last word. This way, we are making sure that the stored fits
    file is always the lates file specified.
---
 bin/table/completion.sh | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/bin/table/completion.sh b/bin/table/completion.sh
index a70e98e..ad61356 100644
--- a/bin/table/completion.sh
+++ b/bin/table/completion.sh
@@ -109,10 +109,15 @@ _gnuastro_autocomplete_expect_number(){
 }
 
 _gnuastro_autocomplete_get_fits_name(){
-    # Get the first fits file among the command line and put it into the
-    # $comp_fits_name variable
+    # Iterate and echo the last fits file among the command line
     # TODO: How about all other fits file extensions?
-    file_name="$(echo "${COMP_WORDS[@]}" | awk -v 
regex="[a-zA-Z0-9]*.[fF][iI][tT][sS]" 'match($0, regex) {print substr($0, 
RSTART, RLENGTH)}')"
+    for w in "${COMP_WORDS[@]}"
+    do
+        temp_name="$(echo "$w" | awk '/[.][fF][iI][tT][sS]$/')"
+        [ -f "$temp_name" ] && file_name="$temp_name"
+    done
+    unset temp_name
+
     if [ -f "$file_name" ]; then
         # Check if file_name is actually an existing fits file. This
         # prevents other functions from failing and producing obscure error
@@ -123,6 +128,7 @@ _gnuastro_autocomplete_get_fits_name(){
         # file everytime bash completion is provoked. Then it will return
         # error if there is no fits name and break functionality.
     fi
+    unset file_name
 }
 
 _gnuastro_autocomplete_get_fits_columns(){
@@ -214,7 +220,7 @@ _gnuastro_asttable_completions(){
             _gnuastro_autocomplete_list_fits_names
             _gnuastro_autocomplete_list_options $PROG_ADDRESS
             ;;
-        -i|--information|-w|--wcsfile)
+        -i|--information)
             if [ -f "$fits_name" ]; then
                 # The user has entered a valid fits file name. So keep on
                 # with suggesting all other options at hand.
@@ -226,17 +232,24 @@ _gnuastro_asttable_completions(){
                 _gnuastro_autocomplete_list_fits_names
             fi
             ;;
-        -c|--column|-r|--range|-s|--sort)
-            # The function below, checks if the user has specified a fits
-            # file in the current commandline. If not, there will be no
-            # response from autocompletion. This might alert the user that
-            # something is going wrong.
+        -L|--catcolumnfile|-w|--wcsfile)
+            # Only suggest a fits filename
+            _gnuastro_autocomplete_list_fits_names
+            ;;
+        -c|--column|-r|--range|-s|--sort|-C|--catcolumns)
+            # The function below returns the columns inside the last fits
+            # file specified in the commandline. If no fits files were
+            # detected, there will be no response from autocompletion. This
+            # might alert the user that something is going wrong.
             _gnuastro_autocomplete_list_fits_columns "$fits_name"
             ;;
         -W|--wcshdu)
             # Description is same as the '--column' option.
             _gnuastro_autocomplete_list_fits_hdu "$fits_name"
             ;;
+        -o|--output)
+            # Do not suggest anything.
+            ;;
         -b|--noblank) ;;
         -h|--hdu) ;;
         *) _gnuastro_autocomplete_list_options $PROG_ADDRESS ;;
@@ -257,10 +270,13 @@ _gnuastro_asttable_completions(){
 >>> prev: '$prev' -- \$3: '$3'
 >>> word: '$word' -- \$2: '$2'
 >>> fits_name: '$fits_name'
+>>> COMP_WORDS: '${COMP_WORDS[@]}'
 >>> COMPREPLY: '${COMPREPLY[@]}'
 *******************************
->>> Line: "$COMP_LINE"
 EOF
+        # Printf should stay outside the 'heredoc' to prevent an extra
+        # newline. As a result, the cursor stays on the same line.
+        printf ">>> Line: %s" "$COMP_LINE"
     fi
 
 }



reply via email to

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