[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
- [gnuastro-commits] master e1c1a4b 18/62: Table: Completion, fix 'wcshdu', (continued)
- [gnuastro-commits] master e1c1a4b 18/62: Table: Completion, fix 'wcshdu', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 6fe9cb6 20/62: Table: Completion, refactor awk regex fits name, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master c593823 23/62: Table: Completion, fix hdu and fits suggestions, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 0420521 04/62: Completion: bug fix in catching the options, Mohammad Akhlaghi, 2021/05/13
- [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 <=
- [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, 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