gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 97d9a1e 09/62: Table: Completion suggests matc


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 97d9a1e 09/62: Table: Completion suggests matching words
Date: Thu, 13 May 2021 22:20:46 -0400 (EDT)

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

    Table: Completion suggests matching words
    
    * Until now, the word that the user wrote was removed by completion.
      With this commit, the suggestions are smarter and actually useful.
---
 bin/table/completion.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/bin/table/completion.sh b/bin/table/completion.sh
index e1fe499..8d4aaac 100644
--- a/bin/table/completion.sh
+++ b/bin/table/completion.sh
@@ -17,9 +17,9 @@ _gnuastro_autocomplete_fits_hdu_read(){
     COMPREPLY=($("$ASTFITS --quiet $1" | awk '{print $2}'))
 }
 
-_gnuastro_autocomplete_fits_list_files(){
+_gnuastro_autocomplete_list_fits_files(){
     # Suggest all 'FITS' files in current directory. Case insensitive.
-    COMPREPLY+=($(compgen -f -X "!*.[fF][iI][tT][sS]"));
+    COMPREPLY=($(compgen -f -X "!*.[fF][iI][tT][sS]"));
 }
 
 _gnuastro_autocomplete_column_read(){
@@ -45,7 +45,9 @@ _gnuastro_file_last_occurance(){
 # astconvolve --help | awk -v pattern="^ *-([a-z]|[A-Z])" 'match($0, pattern) 
{print $0}'
 
 _gnuastro_autocomplete_list_all_options(){
-    COMPREPLY=($($1 --help | awk -v regex=" --+([a-z]|[A-Z]|[0-9])*" 
'match($0, regex) {print substr($0, RSTART, RLENGTH)}'))
+    # The regex variable in the awk program contains the regular expression
+    # pattern that matches all options provided in corresponding program
+    COMPREPLY=($(compgen -W "$($1 --help | awk -v regex=" 
--+([a-z]|[A-Z]|[0-9])*" 'match($0, regex) {print substr($0, RSTART, 
RLENGTH)}')" -- "$word"))
 }
 
 _gnuastro_asttable_completions(){
@@ -65,12 +67,10 @@ _gnuastro_asttable_completions(){
     local prev="${COMP_WORDS[COMP_CWORD-1]}";
 
     case "$word" in
-        -i|--information)
-            _gnuastro_autocomplete_fits_list_files
-        ;;
+        -i|--information) _gnuastro_autocomplete_list_fits_files ;;
         -b|--noblank) ;;
         -h|--hdu) ;;
-        # default case
+        # The default case populates suggestions with all options available
         *) _gnuastro_autocomplete_list_all_options $PROG_NAME ;;
     esac
 



reply via email to

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