gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master afadccf 52/62: Auto-completion: Call ..._last_


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master afadccf 52/62: Auto-completion: Call ..._last_table where needed
Date: Thu, 13 May 2021 22:20:54 -0400 (EDT)

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

    Auto-completion: Call ..._last_table where needed
    
    Until now, the '..._last_table' function ran everytime. This function is
    responsible for populating the $last_table variable. Which means there
    has been a valid FITS or plaintext table file called in the commandline.
    Since we do not need to check for this everytime the script runs, I have
    moved it to more specific places where we need to check the $last_table
    variable. This might help reduce overhead.
    
    Also, I noticed and removed the extra space between the command prompt
    and the user commands.
---
 bin/table/completion.bash | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index 7721469..472549f 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -386,7 +386,7 @@ _gnuastro_autocomplete_list_options(){
 _gnuastro_autocomplete_print_message(){
     if ! [ x"$1" = x ]; then
         printf "\n$1\n"
-        printf "${PS1@P} %s" "$COMP_LINE"
+        printf "${PS1@P}%s" "$COMP_LINE"
     fi
 }
 
@@ -426,10 +426,7 @@ _gnuastro_asttable_completions(){
         prev="${COMP_WORDS[COMP_CWORD-2]}"
     fi
 
-    # If a table has been called until this stage, extract it. The table
-    # name itself will be put in 'last_table' and its possible HDU (if its
-    # was a FITS table), will be put in 'last_table_hdu'.
-    _gnuastro_autocomplete_last_table
+
 
 
     case "$prev" in
@@ -438,6 +435,11 @@ _gnuastro_asttable_completions(){
             _gnuastro_autocomplete_list_options $PROG_NAME
             ;;
         -i|--information)
+            # If a table has been called until this stage, extract it. The 
table
+            # name itself will be put in 'last_table' and its possible HDU (if 
its
+            # was a FITS table), will be put in 'last_table_hdu'.
+            _gnuastro_autocomplete_last_table
+
             # when a file has been given before this, and the
             # '--information' option is called, we should tell the user to
             # avoid trying new options and just press ENTER. Otherwise, we
@@ -461,10 +463,12 @@ _gnuastro_asttable_completions(){
             # 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_last_table
             _gnuastro_autocomplete_list_fits_columns "$last_table"
             ;;
         -W|--wcshdu|-u|--catcolumnhdu|-h|--hdu)
             # Description is same as the '--column' option.
+            _gnuastro_autocomplete_last_table
             _gnuastro_autocomplete_list_fits_hdu "$last_table"
             ;;
         -o|--output|--polygon|-H|--head|-t|--tail| \
@@ -482,10 +486,12 @@ _gnuastro_asttable_completions(){
             # safely press ENTER since this configuration disables all
             # other options. Otherwise, just print all available options.
             if echo "$COMP_LINE" \
-                    | grep -e ' --information' -e ' -i' &> /dev/null \
-                    &&  [ x"$last_table" ]; then
-                _gnuastro_autocomplete_print_message "$infowarning"
-                COMPREPLY=()
+                    | grep -e ' --information' -e ' -i' &> /dev/null; then
+                _gnuastro_autocomplete_last_table
+                if  [ x"$last_table" ]; then
+                    _gnuastro_autocomplete_print_message "$infowarning"
+                    COMPREPLY=()
+                fi
             else
                 _gnuastro_autocomplete_list_options $PROG_NAME
             fi



reply via email to

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