[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master e340452 42/62: Auto-completion: Minor polishin
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master e340452 42/62: Auto-completion: Minor polishing of the warning message |
Date: |
Thu, 13 May 2021 22:20:52 -0400 (EDT) |
branch: master
commit e3404524da5f723ef896e3204328205a661f5c8b
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Auto-completion: Minor polishing of the warning message
Until now, the warning message for the '--information' option was a single
string that was repeated in two places (adding a check for it in general
was a good idea Pedram!). However, based on previous experience, this can
cause bugs if we later edit one of them and forget to the edit the other!
With this commit a new 'infowarning' variable is defined at the top of the
function and message is put there. That variable can now be used anywhere
in the code, and all the time it will have the same value.
Other changes with this commit:
- When the 'last_table' variable is not empty, the existance of its file
has already been checked. So we should just check if its an empty string
or not. Don't forget that checking the existance of a file is
computationally expensive (requires Bash to leave its internal
evironment and go to the operating system!).
- In my case the previous '$' wasn't enough to print the prompt. The new
line simply started with a '$' sign, not my standard prompt. So I added
'${PS1@P}'. As mentioned above it, there is a portability issue here
with older Bash systems. We should find a more portable solution.
- I removed the extra '-----' lines: they are distracting and waste a lot
of valuable terminal lines ;-)!
[To help in future reference to commits related to auto-completion, let's
start the commit title with 'Auto-completion'.]
---
bin/table/completion.bash | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index 7d74e07..3472301 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -353,16 +353,15 @@ _gnuastro_autocomplete_list_options(){
# Prints the message taken as $1 and asks for user action. Then reprints
# the former prompt, which lives in $COMP_LINE.
+#
+# TODO: The newly printed prompt was taken from here:
+# https://stackoverflow.com/questions/22322879/how-to-print-current-bash-prompt
+# This is only available since Bash 4.4 (September 2016). We should find
+# A more low-level/basic operation.
_gnuastro_autocomplete_print_message(){
if ! [ x"$1" = x ]; then
- printf "\n------------------------\n"
- printf "$1"
- printf "\n------------------------\n"
- printf "\n\$ %s" "$COMP_LINE"
- return 0
- else
- # Return 1 if the argument is NULL or not specified.
- return 1
+ printf "\n$1\n"
+ printf "${PS1@P} %s" "$COMP_LINE"
fi
}
@@ -376,6 +375,9 @@ _gnuastro_asttable_completions(){
# Initialize the completion response with null
COMPREPLY=();
+ # Strings used in multiple places.
+ local infowarning="With '--information' (or '-i') all other options are
disabled, you can press ENTER now."
+
# Variable "word", is the current word being completed. "$2" is the
# default value for the current word in completion scripts. But we are
# using the longer form: "${COMP_WORDS[COMP_CWORD]}" for clarity.
@@ -411,18 +413,16 @@ _gnuastro_asttable_completions(){
_gnuastro_autocomplete_list_options $PROG_NAME
;;
-i|--information)
- # 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 [ -f "$last_table" ]; then
- _gnuastro_autocomplete_print_message \
- "The '--information' (or '-i') will disable all other
options. You can safely press ENTER now."
- COMPREPLY=()
- 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 before this, and the
+ # '--information' option is called, we should tell the user to
+ # avoid trying new options and just press ENTER. Otherwise, we
+ # should let the user choose a FITS table (to view its
+ # information).
+ if [ x"$last_table" = x ]; then
_gnuastro_autocomplete_list_fits_names
+ else
+ _gnuastro_autocomplete_print_message "$infowarning"
+ COMPREPLY=()
fi
;;
-L|--catcolumnfile|-w|--wcsfile)
@@ -459,8 +459,7 @@ _gnuastro_asttable_completions(){
if echo "$COMP_LINE" \
| grep -e ' --information' -e ' -i' &> /dev/null \
&& [ -f "$last_table" ]; then
- _gnuastro_autocomplete_print_message \
- "The '--information' (or '-i') will disable all other
options. You can safely press ENTER now."
+ _gnuastro_autocomplete_print_message "$infowarning"
COMPREPLY=()
else
_gnuastro_autocomplete_list_options $PROG_NAME
- [gnuastro-commits] master b947f79 62/62: TAB completion: enabled in Fits program, (continued)
- [gnuastro-commits] master b947f79 62/62: TAB completion: enabled in Fits program, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master acf58c1 58/62: TAB completion: now supported in ConvertType and Convolve, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 9ae830f 34/62: Table: Completion, replace double negative, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 7f1a203 35/62: Book: Autocompletion for developers example, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 6379566 36/62: Book: edits to the Bash auto-completion section, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 9335953 44/62: Auto-completion: Faster fits parse, use 'local', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 284a32e 51/62: Auto-completion: Debug -i, improve performance, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e5707cd 28/62: Table: Completion, all options, update comments, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 88806f2 38/62: bin/table/completion.bash: improvements to find good table name, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 1bf469f 40/62: /bin/table/completion.bash: consider short opt '-i', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e340452 42/62: Auto-completion: Minor polishing of the warning message,
Mohammad Akhlaghi <=
- [gnuastro-commits] master e444941 45/62: Auto-completion: Call astfits/asttable consistently, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 04ee1fe 46/62: Auto-completion: Suggest plaintext tables too, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 3754f1b 47/62: Auto-completion: Human readable arguments, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master ea08fdb 49/62: Auto-completion: return value from last table, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master ece1614 55/62: Auto complete: separated generic functions from Table's recipe, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master ef351da 56/62: TAB completion: now working for Arithmetic, better infrastructure, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master d2bf2c2 60/62: TAB completion: updated documentation and polished the code, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 4412710 29/62: Table: Completions, add missing options from help, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 82e9692 33/62: Book: Update the auto-complete section, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master abe3ca6 43/62: Auto-completion: Smart list fits files, fix var, Mohammad Akhlaghi, 2021/05/13