[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master b5c4f29 27/62: Table: Completion, add options,
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master b5c4f29 27/62: Table: Completion, add options, improve get name |
Date: |
Thu, 13 May 2021 22:20:49 -0400 (EDT) |
branch: master
commit b5c4f2900c3e64ac6773c0cdb2c6e630a3808874
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Table: Completion, add options, improve get name
Until now, the '_gnuastro_autocomplete_get_fits_name' function echoed
the first fits file the user specified. This breaks the behavior for
options such as '--catcolumns' because there might be several fits files
on the command line.
Nevertheless, everytime the user asks for the column names that belongs
to the last fits file specified. Hence, the function will iterate
through all words in the commandline, check them one by one and store
them as a fits file if the name is valid, and then continue the loop
until the last word. This way, we are making sure that the stored fits
file is always the lates file specified.
---
bin/table/completion.sh | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/bin/table/completion.sh b/bin/table/completion.sh
index a70e98e..ad61356 100644
--- a/bin/table/completion.sh
+++ b/bin/table/completion.sh
@@ -109,10 +109,15 @@ _gnuastro_autocomplete_expect_number(){
}
_gnuastro_autocomplete_get_fits_name(){
- # Get the first fits file among the command line and put it into the
- # $comp_fits_name variable
+ # Iterate and echo the last fits file among the command line
# TODO: How about all other fits file extensions?
- file_name="$(echo "${COMP_WORDS[@]}" | awk -v
regex="[a-zA-Z0-9]*.[fF][iI][tT][sS]" 'match($0, regex) {print substr($0,
RSTART, RLENGTH)}')"
+ for w in "${COMP_WORDS[@]}"
+ do
+ temp_name="$(echo "$w" | awk '/[.][fF][iI][tT][sS]$/')"
+ [ -f "$temp_name" ] && file_name="$temp_name"
+ done
+ unset temp_name
+
if [ -f "$file_name" ]; then
# Check if file_name is actually an existing fits file. This
# prevents other functions from failing and producing obscure error
@@ -123,6 +128,7 @@ _gnuastro_autocomplete_get_fits_name(){
# file everytime bash completion is provoked. Then it will return
# error if there is no fits name and break functionality.
fi
+ unset file_name
}
_gnuastro_autocomplete_get_fits_columns(){
@@ -214,7 +220,7 @@ _gnuastro_asttable_completions(){
_gnuastro_autocomplete_list_fits_names
_gnuastro_autocomplete_list_options $PROG_ADDRESS
;;
- -i|--information|-w|--wcsfile)
+ -i|--information)
if [ -f "$fits_name" ]; then
# The user has entered a valid fits file name. So keep on
# with suggesting all other options at hand.
@@ -226,17 +232,24 @@ _gnuastro_asttable_completions(){
_gnuastro_autocomplete_list_fits_names
fi
;;
- -c|--column|-r|--range|-s|--sort)
- # The function below, checks if the user has specified a fits
- # file in the current commandline. If not, there will be no
- # response from autocompletion. This might alert the user that
- # something is going wrong.
+ -L|--catcolumnfile|-w|--wcsfile)
+ # Only suggest a fits filename
+ _gnuastro_autocomplete_list_fits_names
+ ;;
+ -c|--column|-r|--range|-s|--sort|-C|--catcolumns)
+ # The function below returns the columns inside the last fits
+ # 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_list_fits_columns "$fits_name"
;;
-W|--wcshdu)
# Description is same as the '--column' option.
_gnuastro_autocomplete_list_fits_hdu "$fits_name"
;;
+ -o|--output)
+ # Do not suggest anything.
+ ;;
-b|--noblank) ;;
-h|--hdu) ;;
*) _gnuastro_autocomplete_list_options $PROG_ADDRESS ;;
@@ -257,10 +270,13 @@ _gnuastro_asttable_completions(){
>>> prev: '$prev' -- \$3: '$3'
>>> word: '$word' -- \$2: '$2'
>>> fits_name: '$fits_name'
+>>> COMP_WORDS: '${COMP_WORDS[@]}'
>>> COMPREPLY: '${COMPREPLY[@]}'
*******************************
->>> Line: "$COMP_LINE"
EOF
+ # Printf should stay outside the 'heredoc' to prevent an extra
+ # newline. As a result, the cursor stays on the same line.
+ printf ">>> Line: %s" "$COMP_LINE"
fi
}
- [gnuastro-commits] master b391ee8 22/62: Table: Completion, bash4+ long option no space, (continued)
- [gnuastro-commits] master b391ee8 22/62: Table: Completion, bash4+ long option no space, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 97d9a1e 09/62: Table: Completion suggests matching words, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 9ea367b 16/62: Table: Completion, handle '=', do not append space, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 7c95cec 24/62: Table: Completion, better POSIX portability, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 19ebe93 26/62: Table: Completion, improve _compgen, put quotes, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 7b584a4 31/62: Table: Completion, update shebang, fix formatting, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master c259040 39/62: bin/table/completion.bash: Fix '--information', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 6efd4ff 32/62: Book: Add auto-complete to the developing section, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 0e382bc 11/62: Table: Completion, suggest columns inside fits, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 328ab31 19/62: Table: Completion, thoughts on short options, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master b5c4f29 27/62: Table: Completion, add options, improve get name,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 86df9d8 25/62: Table: Completion, custom compgen, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 51daecd 30/62: Table: Completion, update copyright, minor edits, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e690fc5 37/62: Bash completion: renamed fixed file to completion.bash, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 229ac51 41/62: /bin/table/completion.bash: Refactor code, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 50026ec 48/62: Auto-completion: Rename boolean query functions, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 8150e1c 50/62: Auto-completion: Refactor FITS related functions, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master afadccf 52/62: Auto-completion: Call ..._last_table where needed, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 90f08c2 53/62: Auto-completion: Refactor ..._is_table function, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 4598eba 54/62: Auto-completion: clean re-implementation for Table, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 59669d9 61/62: Book: new section on known issues with Crop, Mohammad Akhlaghi, 2021/05/13