1# Bash autocompletion to Gnuastro's Table program. See the comments above 2# 'bin/completion.bash.in' for more. 3# 4# Original author: 5# Pedram Ashofteh Ardakani <pedramardakani@pm.me> 6# Contributing author(s): 7# Mohammad Akhlaghi <mohammad@akhlaghi.org> 8# Copyright (C) 2021 Free Software Foundation, Inc. 9# 10# Gnuastro is free software: you can redistribute it and/or modify it under 11# the terms of the GNU General Public License as published by the Free 12# Software Foundation, either version 3 of the License, or (at your option) 13# any later version. 14# 15# Gnuastro is distributed in the hope that it will be useful, but WITHOUT 16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 18# more details. 19# 20# You should have received a copy of the GNU General Public License along 21# with Gnuastro. If not, see <http://www.gnu.org/ 22 23 24 25 26 27# For debugging 28# 29# See the description in 'bin/completion.bash.in'. 30#source /PATH/TO/GNUASTRO/SRC/bin/completion.bash.in 31#source /PATH/TO/GNUASTRO/BUILD/bin/completion.bash.built 32 33 34 35 36 37####################################################################### 38############ Only for Table (this program) ############ 39####################################################################### 40 41# Dealing with arguments: Table only takes one argument/file. So if a table 42# has been previously given on the command-line only print option names. 43_gnuastro_autocomplete_asttable_arguments(){ 44 local given_file="" 45 if _gnuastro_autocomplete_first_in_arguments table; then 46 _gnuastro_autocomplete_compreply_options_all "" 47 else 48 _gnuastro_autocomplete_compreply_files_certain table "$argument" 49 fi 50} 51 52 53 54 55 56# Fill option value (depends on option). 57_gnuastro_autocomplete_asttable_option_value(){ 58 59 # Internal variables. 60 local fits_file="" 61 local given_hdu="" 62 local given_file="" 63 64 # Keep this in the same order as the output of '--help', for options 65 # with similar operations, keep the order within the '|'s. 66 case "$option_name" in 67 68 # Options that take a columns from the main argument. 69 --column|--noblank|--inpolygon|--outpolygon|--colmetadata|--equal|--notequal) 70 71 # The '--column' and '--noblank' options can (and usually 72 # will!) take more than one column name as value. 73 local continuematch="" 74 case "$option_name" in 75 --column|--noblank) continuematch=yes;; 76 esac 77 78 # Find the suggestions. 79 _gnuastro_autocomplete_given_file_and_hdu table "" --hdu 80 _gnuastro_autocomplete_compreply_table_columns \ 81 "$given_file" "$given_hdu" "$current" "$continuematch" 82 83 # These options take a column name as first value, and the user 84 # should continue with other details. So when there is only one 85 # match, we need to disable the extra space that is printed by 86 # default and also add a ',' to prepare the user for entering 87 # other points. 88 case "$option_name" in 89 --colmetadata|--equal|--notequal) compopt -o nospace;; 90 esac 91 ;; 92 93 -C|--catcolumns) 94 _gnuastro_autocomplete_given_file_and_hdu \ 95 table --catcolumnfile --catcolumnhdu 96 _gnuastro_autocomplete_compreply_table_columns \ 97 "$given_file" "$given_hdu" "$current" 98 ;; 99 100 -h|--hdu) 101 _gnuastro_autocomplete_given_file table "" 102 _gnuastro_autocomplete_compreply_hdus \ 103 table "$given_file" "$current" 104 ;; 105 106 -L|--catcolumnfile) 107 _gnuastro_autocomplete_compreply_files_certain table "$current" 108 ;; 109 110 --searchin) 111 _gnuastro_autocomplete_compreply_searchin "$current" 112 ;; 113 114 -u|--catcolumnhdu) 115 _gnuastro_autocomplete_given_file table --catcolumnfile 116 _gnuastro_autocomplete_compreply_hdus \ 117 table "$given_file" "$current" 118 ;; 119 120 -w|--wcsfile) 121 _gnuastro_autocomplete_compreply_files_certain image "$current" 122 ;; 123 124 -W|--wcshdu) 125 _gnuastro_autocomplete_given_file image --wcsfile 126 _gnuastro_autocomplete_compreply_hdus \ 127 image "$given_file" "$current" 128 ;; 129 130 --tableformat) 131 _gnuastro_autocomplete_compreply_tableformat "$current" 132 ;; 133 134 --copy) 135 ;; 136 esac 137} 138 139 140 141 142 143_gnuastro_autocomplete_asttable(){ 144 145 # The installation directory of Gnuastro. The '@PREFIX@' part will be 146 # replaced automatically during 'make install', with the user's given 147 # requested installation directory. If you are debugging, please 148 # correct it yourself (usually to '/usr/local/bin', but don't commit 149 # this particular change). 150 local gnuastro_prefix="@PREFIX@" 151 152 # Basic initialization. The variables we want to remain inside this 153 # function are given a 'local' here and set inside the 'initialize' 154 # function. The variables are defined above the function that gives 155 # them a value. 156 local prev="" 157 local current="" 158 local argument="" 159 _gnuastro_autocomplete_initialize 160 161 # For a check 162 #echo 163 #echo "prev: $prev" 164 #echo "current: $current" 165 #echo "argument: $argument" 166 167 # Extract the current mode (if the user is giving an argument, option 168 # name, or option value). See the description above this function on 169 # how the mode is set. 170 local options_all="" 171 local option_name="" 172 local option_value="" 173 local option_name_complete=0 174 _gnuastro_autocomplete_mode 175 176 # For a check 177 #echo 178 #echo "argument: $argument" 179 #echo "option_name: $option_name" 180 #echo "option_name_complete: $option_name_complete" 181 #echo "option_value: $option_value" 182 183 # If 'option_name_complete==1', then we are busy filling in the option 184 # value. 185 if [ $option_name_complete = 1 ]; then 186 _gnuastro_autocomplete_asttable_option_value 187 188 # When 'option_name' is not empty (and not yet complete), we are busy 189 # filling in the option name. 190 elif [ x$option_name != x ]; then 191 _gnuastro_autocomplete_compreply_options_all "$option_name" 192 193 # In the case of "none-of-the-above", it is an argument. 194 else 195 _gnuastro_autocomplete_asttable_arguments 196 fi 197} 198 199 200 201 202 203# Define the completion specification, or COMPSPEC: -o bashdefault: Use 204# Bash default completions if nothing is found. -F function: Use this 205# 'function' to generate the given program's completion. 206complete -o bashdefault -F _gnuastro_autocomplete_asttable asttable 207