[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 3754f1b 47/62: Auto-completion: Human readable
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 3754f1b 47/62: Auto-completion: Human readable arguments |
Date: |
Thu, 13 May 2021 22:20:53 -0400 (EDT) |
branch: master
commit 3754f1b32a7d87b489c10d1c8c0aa110f1d3b9ac
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Auto-completion: Human readable arguments
Until now, some functions just used the raw '$1', '$2', etc. to refer to
given arguments. With this commit, some of these arguments are given more
specific names to improve and maintain code readability.
Also, I moved some comment blocks out of functions to respect the coding
standards as Mohammad mentioned previously.
---
bin/table/completion.bash | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/bin/table/completion.bash b/bin/table/completion.bash
index 907c184..cf2998b 100644
--- a/bin/table/completion.bash
+++ b/bin/table/completion.bash
@@ -60,8 +60,9 @@ _gnuastro_asttable="$_gnuastro_prefix/asttable";
# Accepts a FITS filename as input and echoes its headers.
_gnuastro_autocomplete_get_fits_hdu(){
- if [ -f "$1" ]; then
- $_gnuastro_astfits --quiet "$1" | awk '{print $2}'
+ local inputfile="$1"
+ if [ -f $inputfile ]; then
+ $_gnuastro_astfits --quiet $inputfile | awk '{print $2}'
fi
}
@@ -82,9 +83,6 @@ _gnuastro_autocomplete_compgen(){
# the portability.
[[ "$w" =~ $2 ]] && COMPREPLY+=( "$w" )
done
-
- # Uncomment if you want to accept user's current word as a completion
- # [[ -z "${COMPREPLY[*]}" ]] && COMPREPLY+=( "$2" )
}
@@ -94,8 +92,9 @@ _gnuastro_autocomplete_compgen(){
# Checks for the current fits file and puts its headers into completion
# suggestions
_gnuastro_autocomplete_list_fits_hdu(){
- if [ -f "$1" ]; then
- local list=("$(_gnuastro_autocomplete_get_fits_hdu "$1")")
+ local inputfile="$1"
+ if [ -f $inputfile ]; then
+ local list=("$(_gnuastro_autocomplete_get_fits_hdu $inputfile)")
# A custom enhancement for the 'compgen' command. This version will
# have no problem with the dash sign '-'. Because sometimes the
# 'hdu' names might contain dash symbols in them. This ensures that
@@ -119,11 +118,12 @@ _gnuastro_autocomplete_list_fits_hdu(){
#
# The completion can not suggest filenames that contain white space in them
# for the time being.
+#
+# List all files in the current directory. Filter out those that start
+# with the current word in the command line '$word'. Note that the grep
+# option '--color=never' has to be there to prevent passing special
+# characters into '$COMPREPLY'.
_gnuastro_autocomplete_list_fits_names(){
- # List all files in the current directory. Filter out those that start
- # with the current word in the command line '$word'. Note that the grep
- # option '--color=never' has to be there to prevent passing special
- # characters into '$COMPREPLY'.
local files=($(ls | grep -e "^$word" --color=never))
for f in ${files[*]} ; do
if $_gnuastro_astfits "$f" -q &> /dev/null; then COMPREPLY+=("$f"); fi
@@ -171,7 +171,8 @@ _gnuastro_autocomplete_expect_number(){
# opened). Note that FITS files have many possible extensions (see the
# 'gal_fits_name_is_fits' function in 'lib/fits.c').
_gnuastro_autocomplete_file_is_fits(){
- if $_gnuastro_astfits $1 -h0 &> /dev/null; then return 0; else return 1; fi
+ local inputfile="$1"
+ if $_gnuastro_astfits $inputfile -h0 &> /dev/null; then return 0; else
return 1; fi
}
@@ -330,7 +331,7 @@ _gnuastro_autocomplete_get_fits_columns(){
# start with numbers. If so, there will be an unwanted '(hdu:'
# printed in the results. Here, 'awk' will print the second column
# in lines that start with a number.
- "$_gnuastro_asttable" --information "$1" \
+ $_gnuastro_asttable --information "$1" \
| awk 'NR>2' \
| awk '/^[0-9]/ {print $2}'
fi
- [gnuastro-commits] master 7f1a203 35/62: Book: Autocompletion for developers example, (continued)
- [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, 2021/05/13
- [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 <=
- [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
- [gnuastro-commits] master a66e8bb 57/62: TAB completion: BuildProgram support added, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master d7bf627 59/62: TAB completion: support added for CosmicCalculator and Crop, Mohammad Akhlaghi, 2021/05/13