@@ -70,7 +70,10 @@ __pgbackrest_command_options_values_type_info() {
70
70
# If no stanza - return empty string; nothing to complete.
71
71
# May be some delays in getting stanza names.
72
72
__pgbackrest_stanza_values () {
73
- local stanza_values=$( ${script} info --output text 2> /dev/null | awk ' /^stanza:/ {print $2}' )
73
+ # Basic command for 'info' command.
74
+ local info_command=" ${script} info --output text"
75
+ [[ ${config_params} != ' ' ]] && info_command=" ${info_command} ${config_params} "
76
+ local stanza_values=$( ${info_command} 2> /dev/null | awk ' /^stanza:/ {print $2}' )
74
77
echo ${stanza_values}
75
78
}
76
79
@@ -90,15 +93,16 @@ __pgbackrest_repo_content() {
90
93
# archive/dem
91
94
# archive/demo/arch
92
95
[[ ${cur} =~ ${folder_regex} || ${cur} =~ ${path_regex} ]] && cur_value=${cur%/* } && substr_path=" true"
96
+ # Basic command for 'repo-ls' command.
97
+ local repo_ls_command=" ${script} repo-ls --output json"
98
+ # Add config params, if they exists.
99
+ [[ ${config_params} != ' ' ]] && repo_ls_command=" ${repo_ls_command} ${config_params} "
100
+ # For compatibility with versions < v2.33.
101
+ [[ ${repo_params} != ' ' ]] && repo_ls_command=" ${repo_ls_command} ${repo_params} "
93
102
# Get repo content by using 'repo-ls' in json format.
94
103
# For 'repo-get', the content is also obtained via 'repo-ls'.
95
104
# The logic for type 'link' is equivalent to type 'path'.
96
- if [[ ${repo_key} == ' ' ]]; then
97
- # For compatibility with versions < v2.33.
98
- raw_content=$( ${script} repo-ls --output json ${cur_value} 2> /dev/null)
99
- else
100
- raw_content=$( ${script} repo-ls --repo ${repo_key} --output json ${cur_value} 2> /dev/null)
101
- fi
105
+ raw_content=$( ${repo_ls_command} ${cur_value} 2> /dev/null)
102
106
# When incorrect value for '--repo' is used (e.g. '--repo 300'),
103
107
# the command above returns an error, which is discarded, and an empty result.
104
108
# The completion will not show anything.
@@ -123,10 +127,12 @@ _pgbackrest() {
123
127
script=${COMP_WORDS[0]}
124
128
# Repo id allowed values: 1-256.
125
129
# https://pgbackrest.org/command.html#command-repo-ls
126
- # Defaul value '' .
127
- local repo_key =' '
130
+ # If --repo parameter is not set, use the default parameter for pgBackRest or from env .
131
+ local repo_params =' '
128
132
# Regex for check previous argument.
129
133
arg_regex=" ^--([[:alnum:][:punct:]])+$"
134
+ # If --config* parameters are not set, use the default parameters for pgBackRest or from env.
135
+ local config_params=' '
130
136
case $COMP_CWORD in
131
137
1)
132
138
COMPREPLY=($( compgen -W " $( __pgbackrest_commands) " -- ${cur} ) )
@@ -216,6 +222,25 @@ _pgbackrest() {
216
222
COMPREPLY=($( compgen -W " $( __pgbackrest_command_options) " -- ${cur} ) )
217
223
return 0;;
218
224
* )
225
+ local i
226
+ # 0 - script name (pgbackrest), 1 - command (info).
227
+ # There is no need to check them.
228
+ # Example:
229
+ # pgbackrest info --config /tmp/pgbackrest.conf --stanza <TAB>
230
+ for (( i= 2 ; i< ${# COMP_WORDS[@]} - 1 ; i++ )) ; do
231
+ case ${COMP_WORDS[$i]} in
232
+ # Checking whether --config* parameters are set.
233
+ --config)
234
+ config_params=" ${config_params} --config ${COMP_WORDS[$i+1]} " ;;
235
+ --config-include-path)
236
+ config_params=" ${config_params} --config-include-path ${COMP_WORDS[$i+1]} " ;;
237
+ --config-path)
238
+ config_params=" ${config_params} --config-path ${COMP_WORDS[$i+1]} " ;;
239
+ # Checking whether --repo parameter is set.
240
+ --repo)
241
+ repo_params=" ${repo_params} --repo ${COMP_WORDS[$i+1]} " ;;
242
+ esac
243
+ done
219
244
case ${prev} in
220
245
--stanza)
221
246
COMPREPLY=($( compgen -W " $( __pgbackrest_stanza_values) " -- ${cur} ) )
@@ -250,8 +275,6 @@ _pgbackrest() {
250
275
else
251
276
case ${COMP_WORDS[1]} in
252
277
repo-ls | repo-get)
253
- # Check construction like '--repo 2'.
254
- [[ ${COMP_WORDS[COMP_CWORD - 2]} == " --repo" ]] && repo_key=${prev}
255
278
COMPREPLY=($( compgen -W " $( __pgbackrest_repo_content) " -- ${cur} ) )
256
279
compopt -o nospace
257
280
return 0;;
0 commit comments