mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 09:47:58 +00:00
Merge pull request #5341 from oxiedi/fix-zsh-completion-issues
Fix a few issues in zsh completion
This commit is contained in:
commit
b66cad427e
1 changed files with 24 additions and 20 deletions
|
@ -24,7 +24,7 @@
|
||||||
# Style selector used to select a path (when Borg would use either `pp` or `pf`).
|
# Style selector used to select a path (when Borg would use either `pp` or `pf`).
|
||||||
# Default: `fm`.
|
# Default: `fm`.
|
||||||
# repository-suffix
|
# repository-suffix
|
||||||
# This boolean style controls whether to add the `::` suffix to a repository.
|
# This boolean style controls whether to add the `::` auto-removable suffix to a repository.
|
||||||
# Default: `true`.
|
# Default: `true`.
|
||||||
|
|
||||||
(( $+functions[_borg_commands] )) ||
|
(( $+functions[_borg_commands] )) ||
|
||||||
|
@ -169,7 +169,7 @@ _borg-debug() {
|
||||||
|
|
||||||
case $state in
|
case $state in
|
||||||
(command)
|
(command)
|
||||||
debug_commands=(
|
local -a debug_commands=(
|
||||||
'info:show system infos for debugging / bug reports'
|
'info:show system infos for debugging / bug reports'
|
||||||
'dump-archive-items:dump archive items (metadata)'
|
'dump-archive-items:dump archive items (metadata)'
|
||||||
'dump-archive:dump decoded archive metadata'
|
'dump-archive:dump decoded archive metadata'
|
||||||
|
@ -693,7 +693,7 @@ __borg_setup_common_create_options() {
|
||||||
'--comment=[add a comment text to the archive]:COMMENT:_borg_placeholders'
|
'--comment=[add a comment text to the archive]:COMMENT:_borg_placeholders'
|
||||||
'--timestamp=[manually specify the archive creation date/time]:TIMESTAMP:_borg_timestamp'
|
'--timestamp=[manually specify the archive creation date/time]:TIMESTAMP:_borg_timestamp'
|
||||||
'(-c --checkpoint-interval)'{-c,--checkpoint-interval}'=[write checkpoint every SECONDS seconds (default: 1800)]: : _borg_guard_unsigned_number "SECONDS"'
|
'(-c --checkpoint-interval)'{-c,--checkpoint-interval}'=[write checkpoint every SECONDS seconds (default: 1800)]: : _borg_guard_unsigned_number "SECONDS"'
|
||||||
'--chunker-params[specify the chunker parameters]: :_borg_chunker_params_examples'
|
'--chunker-params=[specify the chunker parameters]: :_borg_chunker_params_examples'
|
||||||
'(-C --compression)'{-C,--compression}'=[select compression algorithm]: :_borg_compression'
|
'(-C --compression)'{-C,--compression}'=[select compression algorithm]: :_borg_compression'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -799,7 +799,7 @@ _borg_cached_repositories() {
|
||||||
}'
|
}'
|
||||||
local cachedir=${BORG_CACHE_DIR:-${XDG_CACHE_HOME:-${BORG_BASE_DIR:-$HOME}/.cache}/borg}
|
local cachedir=${BORG_CACHE_DIR:-${XDG_CACHE_HOME:-${BORG_BASE_DIR:-$HOME}/.cache}/borg}
|
||||||
cached_repos=( ${(f)"$(_call_program -p cached-repositories sed -n -E ${(q)sed_script} \
|
cached_repos=( ${(f)"$(_call_program -p cached-repositories sed -n -E ${(q)sed_script} \
|
||||||
"${(q)cachedir}/*/config(N.om)" 2>/dev/null)"} )
|
"${(q)cachedir}/*/config(#qN.om)" 2>/dev/null)"} )
|
||||||
|
|
||||||
if [[ $compstate[quote] != (\'|\") ]]; then
|
if [[ $compstate[quote] != (\'|\") ]]; then
|
||||||
# hide ~BORG_REPO and other scalars
|
# hide ~BORG_REPO and other scalars
|
||||||
|
@ -877,7 +877,7 @@ _borg_repository_or_archive() {
|
||||||
else
|
else
|
||||||
local -a suf
|
local -a suf
|
||||||
if ! compset -S '::*'; then
|
if ! compset -S '::*'; then
|
||||||
if (( $+opts[-a] )) || zstyle -T ":completion:${curcontext}:" repository-suffix; then
|
if (( $+opts[-a] )) || zstyle -T ":completion:${curcontext}:repositories" repository-suffix; then
|
||||||
suf=( -S '::' )
|
suf=( -S '::' )
|
||||||
fi
|
fi
|
||||||
local oqrepo="$PREFIX$SUFFIX"
|
local oqrepo="$PREFIX$SUFFIX"
|
||||||
|
@ -984,12 +984,12 @@ _borg_archive() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if zstyle -t ":completion:${curcontext}:" verbose; then
|
if zstyle -t ":completion:${curcontext}:archives" verbose; then
|
||||||
if (( __borg_archives_need_update || ! $+__borg_archive_names || ! $+__borg_archive_descriptions )); then
|
if (( __borg_archives_need_update || ! $+__borg_archive_names || ! $+__borg_archive_descriptions )); then
|
||||||
__borg_archives_need_update=0
|
__borg_archives_need_update=0
|
||||||
typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
|
typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
|
||||||
local fmt descfmt name desc
|
local fmt descfmt name desc
|
||||||
zstyle -s ":completion:${curcontext}:" archive-description-format descfmt ||
|
zstyle -s ":completion:${curcontext}:archives" archive-description-format descfmt ||
|
||||||
descfmt='{archive:<36} {time} [{id}]'
|
descfmt='{archive:<36} {time} [{id}]'
|
||||||
fmt="{barchive}{NUL}$descfmt{NUL}"
|
fmt="{barchive}{NUL}$descfmt{NUL}"
|
||||||
_call_program -p archive-descriptions \
|
_call_program -p archive-descriptions \
|
||||||
|
@ -1211,11 +1211,12 @@ _borg_style_selector_or_archive_files() {
|
||||||
__borg_style_selectors() {
|
__borg_style_selectors() {
|
||||||
local default_style_selector=$1 path_style_selector
|
local default_style_selector=$1 path_style_selector
|
||||||
shift
|
shift
|
||||||
zstyle -s ":completion:${curcontext%:*}:archive-files" path-style-selector path_style_selector ||
|
zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
|
||||||
path_style_selector='fm'
|
path_style_selector='fm'
|
||||||
local -a disp style_selectors
|
local -a disp
|
||||||
|
local -A style_selectors
|
||||||
__borg_setup_style_selectors
|
__borg_setup_style_selectors
|
||||||
if zstyle -T ":completion:${curcontext}:" verbose; then
|
if zstyle -T ":completion:${curcontext}:style-selectors" verbose; then
|
||||||
local -a style_selector_descriptions extra
|
local -a style_selector_descriptions extra
|
||||||
local k v sep
|
local k v sep
|
||||||
for k v in ${(kv)style_selectors}; do
|
for k v in ${(kv)style_selectors}; do
|
||||||
|
@ -1226,7 +1227,7 @@ __borg_style_selectors() {
|
||||||
(( $#extra )) && v+=" (${(j:, :)extra})"
|
(( $#extra )) && v+=" (${(j:, :)extra})"
|
||||||
style_selector_descriptions+=( "${${k//\\/\\\\}//:/\\:}:$v" )
|
style_selector_descriptions+=( "${${k//\\/\\\\}//:/\\:}:$v" )
|
||||||
done
|
done
|
||||||
zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
|
zstyle -s ":completion:${curcontext}:style-selectors" list-separator sep || sep=--
|
||||||
zformat -a style_selector_descriptions " $sep " $style_selector_descriptions
|
zformat -a style_selector_descriptions " $sep " $style_selector_descriptions
|
||||||
disp=( -ld style_selector_descriptions )
|
disp=( -ld style_selector_descriptions )
|
||||||
fi
|
fi
|
||||||
|
@ -1246,7 +1247,8 @@ __borg_archive_files() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a qargs tmp disp pref style_selectors match mbegin mend archive_files descs
|
local -a qargs tmp disp pref match mbegin mend archive_files descs
|
||||||
|
local -A style_selectors
|
||||||
local k cword fmt descfmt style_selector path_style_selector name descr
|
local k cword fmt descfmt style_selector path_style_selector name descr
|
||||||
|
|
||||||
# take into account exclude options on the command line
|
# take into account exclude options on the command line
|
||||||
|
@ -1270,8 +1272,8 @@ __borg_archive_files() {
|
||||||
|
|
||||||
[[ -z $cword ]] && return 1
|
[[ -z $cword ]] && return 1
|
||||||
|
|
||||||
if zstyle -t ":completion:${curcontext}:" verbose; then
|
if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
|
||||||
zstyle -s ":completion:${curcontext}:" file-description-format descfmt ||
|
zstyle -s ":completion:${curcontext}:archive-files" file-description-format descfmt ||
|
||||||
descfmt='{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}'
|
descfmt='{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}'
|
||||||
fmt="{bpath}{NUL}$descfmt{NUL}"
|
fmt="{bpath}{NUL}$descfmt{NUL}"
|
||||||
else
|
else
|
||||||
|
@ -1292,7 +1294,8 @@ __borg_archive_files() {
|
||||||
[[ -n $style_selector ]] && compset -P "$style_selector:" && pref=( -P "$style_selector:" )
|
[[ -n $style_selector ]] && compset -P "$style_selector:" && pref=( -P "$style_selector:" )
|
||||||
cword="$PREFIX$SUFFIX"
|
cword="$PREFIX$SUFFIX"
|
||||||
[[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
|
[[ $compstate[quote] != (\'|\") ]] && cword=${(Q)cword}
|
||||||
zstyle -s ":completion:${curcontext}:" path-style-selector path_style_selector || path_style_selector='fm'
|
zstyle -s ":completion:${curcontext}:archive-files" path-style-selector path_style_selector ||
|
||||||
|
path_style_selector='fm'
|
||||||
cword="$path_style_selector:$cword"
|
cword="$path_style_selector:$cword"
|
||||||
else
|
else
|
||||||
[[ -z $style_selector ]] && cword="$default_style_selector:$cword"
|
[[ -z $style_selector ]] && cword="$default_style_selector:$cword"
|
||||||
|
@ -1300,7 +1303,7 @@ __borg_archive_files() {
|
||||||
qargs+=( ${(q)cword} )
|
qargs+=( ${(q)cword} )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if zstyle -t ":completion:${curcontext}:" verbose; then
|
if zstyle -t ":completion:${curcontext}:archive-files" verbose; then
|
||||||
_call_program -p archive-file-descriptions ${(q)__borg_command:-borg} list $qargs 2>/dev/null |
|
_call_program -p archive-file-descriptions ${(q)__borg_command:-borg} list $qargs 2>/dev/null |
|
||||||
while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
|
while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
|
||||||
archive_files+=( $name )
|
archive_files+=( $name )
|
||||||
|
@ -1341,7 +1344,8 @@ __borg_pattern_files() {
|
||||||
local paths_varname=$1
|
local paths_varname=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
local -a args style_selectors
|
local -a args
|
||||||
|
local -A style_selectors
|
||||||
__borg_setup_style_selectors
|
__borg_setup_style_selectors
|
||||||
local pr_pat='[RP\+\-\!]' ss_pat="(${(j:|:)${(@kb)style_selectors}}):"
|
local pr_pat='[RP\+\-\!]' ss_pat="(${(j:|:)${(@kb)style_selectors}}):"
|
||||||
local prs_pat="$pr_pat #"
|
local prs_pat="$pr_pat #"
|
||||||
|
@ -1533,7 +1537,7 @@ _borg_statuschars() {
|
||||||
'i[backup data was read from standard input (stdin)]' \
|
'i[backup data was read from standard input (stdin)]' \
|
||||||
'-[dry run, item was not backed up]' \
|
'-[dry run, item was not backed up]' \
|
||||||
'x[excluded, item was not backed up]' \
|
'x[excluded, item was not backed up]' \
|
||||||
'?[missing status code]' \
|
'?[missing status code]'
|
||||||
}
|
}
|
||||||
|
|
||||||
(( $+functions[_borg_quota_suffixes] )) ||
|
(( $+functions[_borg_quota_suffixes] )) ||
|
||||||
|
|
Loading…
Reference in a new issue