1
1
#! /usr/bin/env bash
2
2
#
3
3
# Bash completion support for pgBackRest (https://pgbackrest.org/)
4
+ # See 'allow-list' in https://github.com/pgbackrest/pgbackrest/blob/main/src/build/config/config.yaml
4
5
5
6
# For all executed commands stderr is sent to /dev/null.
6
7
# Errors are not needed for completion.
@@ -34,8 +35,28 @@ __pgbackrest_command_options_values_output() {
34
35
echo " text" $' \n ' " json"
35
36
}
36
37
37
- # If no stanza - return empty string; nothing to complete
38
- # May be some delays in getting stanza names
38
+ # The '--buffer-size' displays values in the user friendly format starting from pgBackRest v2.37.
39
+ # In earlier versions, values in bytes will be substituted.
40
+ # https://github.com/pgbackrest/pgbackrest/pull/1557
41
+ __pgbackrest_command_options_values_buffer_size (){
42
+ local buffer_size_option_values
43
+ # Regex for valid values like:
44
+ # 16384,
45
+ # 16777216.
46
+ # 16KiB,
47
+ # 16MiB.
48
+ local size_regex=" ^[[:digit:]]+([[:alpha:]]+)?[[:punct:]]$"
49
+ # Get full string with all values.
50
+ local buffer_size_content=$( ${script} help ${COMP_WORDS[1]} ${prev# --} 2> /dev/null | awk ' /^Allowed values([[:graph:]]|[[:space:]])/ {print $0; getline; print $0}' )
51
+ # Parse string and add to array result.
52
+ for line in ${buffer_size_content} ; do
53
+ [[ ${line} =~ ${size_regex} ]] && buffer_size_option_values+=(${line/ [[:punct:]]/ } )
54
+ done
55
+ echo ${buffer_size_option_values[@]}
56
+ }
57
+
58
+ # If no stanza - return empty string; nothing to complete.
59
+ # May be some delays in getting stanza names.
39
60
__pgbackrest_stanza_values () {
40
61
local stanza_values=$( ${script} info --output text 2> /dev/null | awk ' /^stanza:/ {print $2}' )
41
62
echo ${stanza_values}
@@ -110,7 +131,7 @@ _pgbackrest() {
110
131
return 0;;
111
132
repo-ls | repo-get)
112
133
# Because '--repo' flag not specified yet,
113
- # Get repo content from the highest priority repository (e.g. repo1)
134
+ # get repo content from the highest priority repository (e.g. repo1).
114
135
COMPREPLY=($( compgen -W " $( __pgbackrest_repo_content) " -- ${cur} ) )
115
136
compopt -o nospace
116
137
return 0;;
@@ -131,6 +152,9 @@ _pgbackrest() {
131
152
--output)
132
153
COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values_output) " -- ${cur} ) )
133
154
return 0;;
155
+ --buffer-size)
156
+ COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values_buffer_size) " -- ${cur} ) )
157
+ return 0;;
134
158
* )
135
159
if [[ ${prev} =~ ${arg_regex} ]]; then
136
160
COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values) " -- ${cur} ) )
@@ -164,6 +188,9 @@ _pgbackrest() {
164
188
--output)
165
189
COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values_output) " -- ${cur} ) )
166
190
return 0;;
191
+ --buffer-size)
192
+ COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values_buffer_size) " -- ${cur} ) )
193
+ return 0;;
167
194
* )
168
195
if [[ ${prev} =~ ${arg_regex} ]]; then
169
196
COMPREPLY=($( compgen -W " $( __pgbackrest_command_options_values) " -- ${cur} ) )
@@ -185,4 +212,5 @@ _pgbackrest() {
185
212
esac
186
213
}
187
214
188
- complete -F _pgbackrest pgbackrest
215
+ # -o nosort - disable bash sorting, use pgBackRest output sorting.
216
+ complete -o nosort -F _pgbackrest pgbackrest
0 commit comments