gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 9ea367b 16/62: Table: Completion, handle '=',


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 9ea367b 16/62: Table: Completion, handle '=', do not append space
Date: Thu, 13 May 2021 22:20:47 -0400 (EDT)

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

    Table: Completion, handle '=', do not append space
    
    * Until now, the completion suggested the long options without the equal
      sign. Using equal sign for long options is recommended by GNU. So it
      would be nice to respect this. With this commit, no space is appended
      at the end of each suggestion. This means that the users have to enter
      space each time they are done with a command. In addition, pressing
      <TAB> successively will not fill up the entire commandline!
---
 bin/table/completion.sh | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/bin/table/completion.sh b/bin/table/completion.sh
index 219dd0d..d31481d 100644
--- a/bin/table/completion.sh
+++ b/bin/table/completion.sh
@@ -69,7 +69,7 @@ _gnuastro_autocomplete_list_fits_columns(){
     # its column names
     if [ -f "$1" ]; then
         local list="$(_gnuastro_autocomplete_get_fits_columns $1)"
-        COMPREPLY=($(compgen -W "$list" -- "$word"))
+        COMPREPLY=($(compgen -W "$list"))
     fi
 }
 
@@ -84,7 +84,7 @@ _gnuastro_autocomplete_get_file(){
 _gnuastro_autocomplete_list_options(){
     # Accept the command name and its absolute path, run the --help option
     # and print all long options available.
-    local list="$($1 --help | awk -v regex=" --+[a-zA-Z0-9]*" 'match($0, 
regex) {print substr($0, RSTART, RLENGTH)}')"
+    local list="$($1 --help | awk -v regex=" --+[a-zA-Z0-9]*=?" 'match($0, 
regex) {print substr($0, RSTART, RLENGTH)}')"
     COMPREPLY=($(compgen -W "$list" -- "$word"))
 }
 
@@ -104,14 +104,6 @@ _gnuastro_asttable_completions(){
     # Variable "prev" is the word just before the current word
     local prev="${COMP_WORDS[COMP_CWORD-1]}";
 
-    # In case the option contains an equal sign '=' complexities arise.
-    # This is because bash considers '=' as a wordbreak. The WORDBREAK
-    # variable can be altered but it is discouraged. Instead, we will treat
-    # each case carefully.
-    #
-    if [ "$prev" == "=" ]; then prev="${COMP_WORDS[COMP_CWORD-2]}"; fi
-    if [ "$word" == "=" ]; then word="$prev"; fi
-
     # A quick check to see if there is already a fits file name invoked in
     # the current commandline. This means the order of commands does matter
     # in this bash completion. If we do not want this, we should implement
@@ -121,15 +113,16 @@ _gnuastro_asttable_completions(){
     # TODO: Prettify the code syntax, shorter ones on top
     case "$prev" in
         -i|--information) _gnuastro_autocomplete_list_fits_names ;;
-        -c|--column)
-        # echo "fits_name: $fits_name"
-        # _gnuastro_autocomplete_list_fits_columns "$fits_name"
-            local fits_columns="$(_gnuastro_autocomplete_get_fits_columns 
'$fits_name')"
-            printf "\n*** DEBUG ***\n>>> prev: $prev\n>>> word: $word\n>>> 
line: ${COMP_LINE[@]}"
-        ;;
-            -w|--wcsfile) _gnuastro_autocomplete_list_fits_names ;;
-            -W|--wcshdu) _gnuastro_autocomplete_list_fits_hdu "$fits_name"
-            ;; -b|--noblank) ;; -h|--hdu) ;; *)
-            _gnuastro_autocomplete_list_options $PROG_NAME ;; esac }
-
-complete -F _gnuastro_asttable_completions asttable
+        -c|--column) _gnuastro_autocomplete_list_fits_columns "$fits_name" ;;
+        -w|--wcsfile) _gnuastro_autocomplete_list_fits_names ;;
+        -W|--wcshdu) _gnuastro_autocomplete_list_fits_hdu "$fits_name" ;;
+        -b|--noblank) ;;
+        -h|--hdu) ;;
+        *) _gnuastro_autocomplete_list_options $PROG_NAME ;;
+    esac
+
+    # Debugging purpose:
+    # printf "\n*** DEBUG ***\n>>> prev: $prev \t \$3: $3\n>>> word: $word \t 
\$2: $2\n>>> line: ${COMP_LINE[@]}"
+}
+
+complete -F _gnuastro_asttable_completions -o nospace asttable



reply via email to

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