[Top][All Lists]

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

[gnuastro-commits] master 284a32e 51/62: Auto-completion: Debug -i, impr

From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 284a32e 51/62: Auto-completion: Debug -i, improve performance
Date: Thu, 13 May 2021 22:20:54 -0400 (EDT)

branch: master
commit 284a32eb25310714f38bc64bd3152c2c0f19eddc
Author: Pedram Ashofteh Ardakani <>
Commit: Mohammad Akhlaghi <>

    Auto-completion: Debug -i, improve performance
    Until now, autocompletion checked if there is a valid FITS file or a
    plaintext table available while also the '-i' or '--information' option
    is called. In this case, it would print a warning message that it is safe
    to press ENTER since all other options will be disabled by the 'table'
    program. However, this behavior broke in previous commits. This commit
    fixes the problem.
    Also, previously the 'awk' command in the '..._last_table' function would
    print all the words in the command line -- named as 'token'. This
    includes the short and long options. The problem is that bash is later
    instructed to check if each 'token' is a valid file -- [ -f $token]. As
    Mohammad pointed out before, this is a computationaly exhaustive process.
    So, we would only need to check tokens that we already know are not the
    program options! These tokens would start with a dash '-'. Hence, I have
    added a regex condition check in the 'awk' program to take care of that.
    Now, it will only print tokens NOT starting with a '-' sign.
 bin/table/completion.bash | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index 5638665..7721469 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -273,7 +273,8 @@ _gnuastro_autocomplete_last_table(){
     # Parse the tokens in reverse.
     for token in $(echo "${COMP_WORDS[@]}" \
-                    | awk '{for(i=NF;i>1;--i) printf "%s ", $i}')
+                    | awk '{for(i=NF;i>1;--i)
+                          if ($i !~ /^-/) printf "%s ", $i}')
         # First, make sure it is an existing file.
         if [ -f $token ]; then
@@ -482,7 +483,7 @@ _gnuastro_asttable_completions(){
             # other options. Otherwise, just print all available options.
             if echo "$COMP_LINE" \
                     | grep -e ' --information' -e ' -i' &> /dev/null \
-                    &&  [ -f "$last_table" ]; then
+                    &&  [ x"$last_table" ]; then
                 _gnuastro_autocomplete_print_message "$infowarning"

reply via email to

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