Skip to content

Commit 38a328b

Browse files
Merge pull request #8858 from ThomasWaldmann/shell-archive-completions
some fixes for shell completions
2 parents d197810 + a4761f9 commit 38a328b

File tree

2 files changed

+32
-81
lines changed

2 files changed

+32
-81
lines changed

scripts/shell_completions/bash/borg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ _borg()
160160
local opts="-n --dry-run --other-repo --upgrader ${common_opts} -a --match-archives ${archive_filter_opts}"
161161
;;
162162
*' serve '*)
163-
local opts="--restrict-to-path --restrict-to-repository --append-only --storage-quota ${common_opts}"
163+
local opts="--restrict-to-path --restrict-to-repository ${common_opts}"
164164
;;
165165
*' tag '*)
166166
local opts="--set --add --remove -a --match-archives ${archive_filter_opts} ${common_opts}"

scripts/shell_completions/zsh/_borg

Lines changed: 31 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ _borg-delete() {
277277
$common_archive_filters_options \
278278
$common_options \
279279
':ARCHIVE: _borg_archive' \
280-
'*:ARCHIVE: _borg_archive "${line[1]%%::*}"'
280+
'*:ARCHIVE: _borg_archive'
281281
}
282282

283283
(( $+functions[_borg-diff] )) ||
@@ -294,7 +294,7 @@ _borg-diff() {
294294
$common_exclude_options \
295295
$common_options \
296296
':ARCHIVE1: _borg_archive -a' \
297-
':ARCHIVE2: _borg_archive "${line[1]%%::*}"' \
297+
':ARCHIVE2: _borg_archive' \
298298
'*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
299299
}
300300

@@ -453,7 +453,7 @@ _borg-list() {
453453
$common_archive_filters_options \
454454
$common_exclude_options \
455455
$common_options \
456-
':ARCHIVE: _borg_archive' \
456+
':ARCHIVE: _borg_archive -a' \
457457
'*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
458458
}
459459

@@ -511,7 +511,7 @@ _borg-recreate() {
511511

512512
_arguments -s -w -S : \
513513
$common_create_options \
514-
'--target=[create a new archive with the name ARCHIVE]:ARCHIVE: _borg_placeholder_or_archive "${line[1]%%\:\:*}"' \
514+
'--target=[create a new archive with the name ARCHIVE]:ARCHIVE: _borg_placeholder_or_archive' \
515515
$common_options \
516516
':ARCHIVE: _borg_archive' \
517517
'*: : _borg_style_selector_or_archive_files -e "$line[1]" pp'
@@ -636,7 +636,7 @@ _borg-tag() {
636636
$common_archive_filters_options \
637637
$common_options \
638638
':ARCHIVE: _borg_archive' \
639-
'*:ARCHIVE: _borg_archive "${line[1]%%::*}"'
639+
'*:ARCHIVE: _borg_archive'
640640
}
641641

642642
(( $+functions[_borg-transfer] )) ||
@@ -814,8 +814,6 @@ __borg_setup_common_repo_options() {
814814
__borg_setup_common_options
815815
typeset -ga common_repo_options=(
816816
$common_options
817-
'--append-only[only allow appending to repository segment files]'
818-
'--storage-quota=[override storage quota of the repository]: :_borg_quota_suffixes'
819817
)
820818
}
821819

@@ -1017,70 +1015,33 @@ _borg_archive() {
10171015
local -a sort_by=( --sort-by=${(M)^asort:#(timestamp|name|id)} )
10181016
# NOTE: in case of option repetition, the later one takes precedence
10191017

1020-
if (( ! $+__borg_archives_need_update )); then
1021-
comppostfuncs+=( __borg_unset_archives_need_update )
1022-
typeset -gHi __borg_archives_need_update=1
1023-
if (( ! $#archive_filters && ! $+opts[-n] )); then
1024-
local erepo
1025-
[[ -n $1 ]] && __borg_expand_path ${(Q)qrepo} erepo
1026-
local -a newest_file=( $erepo/(hints|index|integrity).<1->(#qN.om[1]) )
1027-
if [[ -n $newest_file ]]; then
1028-
if zmodload -F zsh/stat b:zstat 2>/dev/null; then
1029-
local -a stats
1030-
zstat -A stats +mtime $newest_file
1031-
local -i mtime=$stats[1]
1032-
if [[ $__borg_prev_repo == $erepo
1033-
&& __borg_prev_mtime -ge mtime
1034-
&& $__borg_prev_order == $reversed_order
1035-
&& $__borg_prev_sort_by == $sort_by ]]
1036-
then
1037-
__borg_archives_need_update=0
1038-
else
1039-
typeset -gH __borg_prev_repo=$erepo
1040-
typeset -gHi __borg_prev_mtime=mtime __borg_prev_order=reversed_order
1041-
typeset -gHa __borg_prev_sort_by=( $sort_by )
1042-
fi
1043-
fi
1044-
fi
1045-
else
1046-
unset __borg_prev_{repo,mtime,order,sort_by}
1047-
comppostfuncs+=( __borg_unset_archives )
1048-
fi
1049-
fi
1050-
10511018
if zstyle -t ":completion:${curcontext}:archives" verbose; then
1052-
if (( __borg_archives_need_update || ! $+__borg_archive_names || ! $+__borg_archive_descriptions )); then
1053-
__borg_archives_need_update=0
1054-
typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
1055-
local fmt descfmt name desc
1056-
zstyle -s ":completion:${curcontext}:archives" archive-description-format descfmt ||
1057-
descfmt='{archive:<36} {time} [{id}]'
1058-
fmt="{barchive}{NUL}$descfmt{NUL}"
1059-
_call_program -p archive-descriptions \
1060-
${(q)__borg_command:-borg} repo-list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null |
1061-
while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
1062-
__borg_archive_names[1,0]=( $name )
1063-
__borg_archive_descriptions[1,0]=( "$descr" )
1064-
done
1065-
(( $pipestatus[1] )) && {
1066-
_message "couldn't list repository: ${(Q)qrepo}"
1067-
unset __borg_prev_{repo,mtime,order,sort_by}
1068-
return 1
1069-
}
1070-
(( ! reversed_order )) &&
1071-
__borg_archive_names=( "${(@aO)__borg_archive_names}" ) &&
1072-
__borg_archive_descriptions=( "${(@aO)__borg_archive_descriptions}" )
1073-
fi
1019+
typeset -gHa __borg_archive_names=() __borg_archive_descriptions=()
1020+
local fmt descfmt name desc
1021+
zstyle -s ":completion:${curcontext}:archives" archive-description-format descfmt ||
1022+
descfmt='{id:.8} {time} {archive:<15} {tags:<10} {username:<10} {hostname:<10} {comment:.40}'
1023+
fmt="{archive}{NUL}$descfmt{NUL}"
1024+
_call_program -p archive-descriptions \
1025+
${(q)__borg_command:-borg} repo-list --format=${(q)fmt} ${(q)sort_by} $archive_filters --repo $qrepo 2>/dev/null |
1026+
while IFS= read -r -d $'\0' name && IFS= read -r -d $'\0' descr; do
1027+
__borg_archive_names[1,0]=( $name )
1028+
__borg_archive_descriptions[1,0]=( "$descr" )
1029+
done
1030+
(( $pipestatus[1] )) && {
1031+
_message "couldn't list repository: ${(Q)qrepo}"
1032+
return 1
1033+
}
1034+
(( ! reversed_order )) &&
1035+
__borg_archive_names=( "${(@aO)__borg_archive_names}" ) &&
1036+
__borg_archive_descriptions=( "${(@aO)__borg_archive_descriptions}" )
10741037
disp+=( -ld __borg_archive_descriptions )
1075-
elif (( __borg_archives_need_update || ! $+__borg_archive_names )); then
1076-
__borg_archives_need_update=0
1038+
else
10771039
typeset -gHa __borg_archive_names=()
1078-
local fmt='{barchive}{NUL}'
1040+
local fmt='{archive}{NUL}'
10791041
__borg_archive_names=( ${(@0aO)"$(_call_program -p archives \
1080-
${(q)__borg_command:-borg} repo-list --format=${(q)fmt} ${(q)sort_by} $archive_filters $qrepo 2>/dev/null)"} )
1042+
${(q)__borg_command:-borg} repo-list --format=${(q)fmt} ${(q)sort_by} $archive_filters --repo $qrepo 2>/dev/null)"} )
10811043
(( $pipestatus[1] )) && {
10821044
_message "couldn't list repository: ${(Q)qrepo}"
1083-
unset __borg_prev_{repo,mtime,order,sort_by}
10841045
return 1
10851046
}
10861047
(( ! reversed_order )) &&
@@ -1098,15 +1059,6 @@ _borg_archive() {
10981059
return 1
10991060
}
11001061

1101-
(( $+functions[__borg_unset_archives] )) ||
1102-
__borg_unset_archives() {
1103-
unset __borg_archive_names __borg_archive_descriptions
1104-
}
1105-
1106-
(( $+functions[__borg_unset_archives_need_update] )) ||
1107-
__borg_unset_archives_need_update() {
1108-
unset __borg_archives_need_update
1109-
}
11101062

11111063
(( $+functions[__borg_expand_path] )) ||
11121064
__borg_expand_path() {
@@ -1150,10 +1102,10 @@ _borg_placeholders() {
11501102

11511103
(( $+functions[_borg_format_keys] )) ||
11521104
_borg_format_keys() {
1153-
local repo_or_arch=${(Q)1}
1105+
local archive=${(Q)1}
11541106

11551107
local -a keys=( NEWLINE NL NUL SPACE TAB CR LF )
1156-
local -a repository_keys=( archive name barchive comment bcomment id start time end command_line hostname username )
1108+
local -a repository_keys=( archive name comment bcomment id start time end command_line hostname username )
11571109
local -a archive_keys=( type mode uid gid user group path bpath source linktarget flags size csize dsize dcsize
11581110
num_chunks unique_chunks mtime ctime atime isomtime isoctime isoatime blake2b blake2s md5 sha1 sha224 sha256 sha384
11591111
sha3_224 sha3_256 sha3_384 sha3_512 sha512 shake_128 shake_256 archiveid archivename extra health )
@@ -1162,10 +1114,9 @@ _borg_format_keys() {
11621114
akeys='archive-keys:archive keys:compadd -a archive_keys'
11631115
rkeys='repository-keys:repository keys:compadd -a repository_keys'
11641116
local -a alts=( 'keys:keys:compadd -a keys' )
1165-
if [[ $repo_or_arch == *::?* ]]; then
1117+
# If an archive is specified, show archive keys, otherwise show both repository and archive keys
1118+
if [[ -n $archive ]]; then
11661119
alts+=( $akeys )
1167-
elif [[ -n $repo_or_arch ]]; then
1168-
alts+=( $rkeys )
11691120
else
11701121
alts+=( $rkeys $akeys )
11711122
fi
@@ -1295,7 +1246,7 @@ __borg_archive_files() {
12951246
local arch=$1 default_style_selector=$2
12961247
shift 2
12971248

1298-
if [[ -z $arch || $arch != *::?* ]]; then
1249+
if [[ -z $arch ]]; then
12991250
_message 'no archive specified'
13001251
return 1
13011252
fi

0 commit comments

Comments
 (0)