[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master c259040 39/62: bin/table/completion.bash: Fix
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master c259040 39/62: bin/table/completion.bash: Fix '--information' |
Date: |
Thu, 13 May 2021 22:20:51 -0400 (EDT) |
branch: master
commit c25904020f57c8534401a2c1a93f39e50f6e1784
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
bin/table/completion.bash: Fix '--information'
Until now, if the user asked for information of a fits file, the
autocompletion would still print other options as suggestions. With this
commit, autocompletion checks if the '--information' option is invoked
while also a valid fits file has been specified. In this case, the
autocompletion will cease printing other suggestions, and keep telling
the user that they can just press ENTER and move on.
FIX: This will fix the problem mentioned in the commit below:
e18d46e476dab290087ca7bcb1dd8f096f59923e
The error showed up because there was no variable $NAME, replaced it with
$PROG_NAME and the error '-bash: command : not found' went away.
---
bin/table/completion.bash | 100 +++++++++++++++++++++++-----------------------
1 file changed, 50 insertions(+), 50 deletions(-)
diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index b94338b..2384b1b 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -101,6 +101,8 @@ _gnuastro_autocomplete_list_fits_hdu(){
# 'hdu' names might contain dash symbols in them. This ensures that
# all of them are suggested.
_gnuastro_autocomplete_compgen "${list[@]}" "$word"
+ # TODO: If using `local` is allowed, remove the `unset` commands
+ # and declare variables as `local` instead
unset list
fi
}
@@ -384,56 +386,54 @@ _gnuastro_asttable_completions(){
# was a FITS table), will be put in 'last_table_hdu'.
_gnuastro_autocomplete_last_table
- # TODO: Prettify the code syntax, shorter ones on top
- case "$prev" in
- asttable)
- _gnuastro_autocomplete_list_fits_names
- _gnuastro_autocomplete_list_options $PROG_NAME
- ;;
- -i|--information)
- if [ -f "$last_table" ]; then
- # The extra, empty array element is a hack so Bash prints a
- # warning in a separate line and waits for input.
- #
- # PROBLEM: In this scenario (when a File has been given,
- # and the information option is called, we should tell the
- # user to avoid trying new options and just press
- # ENTER. But I can't get the script to do this!
- COMPREPLY+=("The '--information' (or '-i') will disable all
other options, you can safely press ENTER now", "")
- else
- # Check if the user has already specified a fits file. If
- # the _gnuastro_autocomplete_get_file_name echoes an empty
- # response, it means no fits files were specified.
+ # when a File has been given, and the information option is called, we
+ # should tell the user to avoid trying new options and just press ENTER
+ if [[ "$COMP_LINE" =~ "--information" ]] && [ -f "$last_table" ]; then
+ printf "\nThe '--information' (or '-i') will disable all other
options, you can safely press ENTER now.\n%s" "$COMP_LINE"
+ COMPREPLY=()
+ else
+ # Regular completion
+ case "$prev" in
+ asttable)
_gnuastro_autocomplete_list_fits_names
- fi
- ;;
- -L|--catcolumnfile|-w|--wcsfile)
- # Only suggest a fits filename
- _gnuastro_autocomplete_list_fits_names
- ;;
- -c|--column|-r|--range|-s|--sort|-C|--catcolumns| \
- -m|--colmetadata|--inpolygon|--outpolygon| \
- -e|--equal|-n|--notequal|-b|--noblank|--searchin)
- # 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 "$last_table"
- ;;
- -W|--wcshdu|-u|--catcolumnhdu|-h|--hdu)
- # Description is same as the '--column' option.
- _gnuastro_autocomplete_list_fits_hdu "$last_table"
- ;;
- -o|--output|--polygon|-H|--head|-t|--tail| \
- --onlyversion|-N|--numthreads|--minmapsize)
- # Do not suggest anything.
- ;;
- --config)
- # Suggest config files
- COMPREPLY=($(compgen -f -X "!*.[cC][oO][nN][fF]" -- "$word"))
- ;;
- *) _gnuastro_autocomplete_list_options $NAME ;;
- esac
+ _gnuastro_autocomplete_list_options $PROG_NAME
+ ;;
+ -i|--information)
+ if ! [ -f "$last_table" ]; then
+ # Check if the user has already specified a fits file. If
+ # the _gnuastro_autocomplete_get_file_name echoes an empty
+ # response, it means no fits files were specified.
+ _gnuastro_autocomplete_list_fits_names
+ fi
+ ;;
+ -L|--catcolumnfile|-w|--wcsfile)
+ # Only suggest a fits filename
+ _gnuastro_autocomplete_list_fits_names
+ ;;
+ -c|--column|-r|--range|-s|--sort|-C|--catcolumns| \
+ -m|--colmetadata|--inpolygon|--outpolygon| \
+ -e|--equal|-n|--notequal|-b|--noblank|--searchin)
+ # 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 "$last_table"
+ ;;
+ -W|--wcshdu|-u|--catcolumnhdu|-h|--hdu)
+ # Description is same as the '--column' option.
+ _gnuastro_autocomplete_list_fits_hdu "$last_table"
+ ;;
+ -o|--output|--polygon|-H|--head|-t|--tail| \
+ --onlyversion|-N|--numthreads|--minmapsize)
+ # Do not suggest anything.
+ ;;
+ --config)
+ # Suggest config files
+ COMPREPLY=($(compgen -f -X "!*.[cC][oO][nN][fF]" -- "$word"))
+ ;;
+ *) _gnuastro_autocomplete_list_options $PROG_NAME ;;
+ esac
+ fi
if [[ "${COMPREPLY[@]}" =~ "=" ]]; then
# Do not append 'space' character to the end of line in case there
@@ -443,7 +443,7 @@ _gnuastro_asttable_completions(){
fi
# Be verbose in debugging mode, where $db is set to '0'.
- if [ 1 = 0 ]; then
+ if [ $_gnuastro_completion_debug = 0 ]; then
cat <<EOF
************ DEBUG ************
- [gnuastro-commits] master 3d8e96d 10/62: Table: Fix completion issue, (continued)
- [gnuastro-commits] master 3d8e96d 10/62: Table: Fix completion issue, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master f2ccd6e 12/62: Table: Completion, fix reading fits column, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master d0e1362 14/62: Table: Completion, better function name, copyright, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 7ad725a 21/62: Table: Completion, fix hdu and fits suggestions, Mohammad Akhlaghi, 2021/05/13
- [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 <=
- [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, 2021/05/13
- [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