gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master abe3ca6 43/62: Auto-completion: Smart list fit


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master abe3ca6 43/62: Auto-completion: Smart list fits files, fix var
Date: Thu, 13 May 2021 22:20:52 -0400 (EDT)

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

    Auto-completion: Smart list fits files, fix var
    
    Until now, the function responsible for listing the fits files only
    checked if the file extension ended with 'fits'. This is not a rebust
    test, because other fits files -- that might have different extensions
    or no extensions at all -- would be left out.
    
    With this commit, I used 'astfits' program return value to check their
    validity regardless of their name or extension. However, this has a bit
    of overhead and slows response. We can ignore it if it is not that
    significant, and will not ruin user experience.
    
    Also, I replaced a hard-coded value with intended $inputfile variable.
---
 bin/table/completion.bash | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index 3472301..694b95d 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -123,7 +123,14 @@ _gnuastro_autocomplete_list_fits_hdu(){
 # The completion can not suggest filenames that contain white space in them
 # for the time being.
 _gnuastro_autocomplete_list_fits_names(){
-    COMPREPLY+=($(compgen -f -X "!*.[fF][iI][tT][sS]" -- "$word"))
+    # List all files in the current directory. Filter out those that start
+    # with the current word in the command line '$word'. Note that the grep
+    # option '--color=never' has to be there to prevent passing special
+    # characters into '$COMPREPLY'.
+    local files=($(ls | grep -e "^$word" --color=never))
+    for f in ${files[*]} ; do
+        if astfits $f &> /dev/null; then COMPREPLY+=("$f"); fi
+    done
 }
 
 
@@ -207,11 +214,11 @@ _gnuastro_autocomplete_option_value(){
 _gnuastro_autocomplete_plaintext_is_table(){
 
     # For easy reading.
-    local inputfile=$1
+    local inputfile="$1"
 
     # If the file is not plain-text, it will contain an 'executable' or
     # 'binary' in the output of the 'file' command.
-    if file samaeh-abstract.txt \
+    if file $inputfile \
             | grep 'executable\|binary' &> /dev/null; then
         return 1
     else



reply via email to

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