1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-25 07:23:28 +00:00

Merge pull request #4443 from SanskritFritz/1.1-maint

Shell completions: borg diff second archive
This commit is contained in:
TW 2019-03-15 19:02:40 +01:00 committed by GitHub
commit db271f768f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 8 deletions

View file

@ -153,6 +153,12 @@ _borg()
repository_name=${prevprev} repository_name=${prevprev}
typed_word=${cur} typed_word=${cur}
fi fi
# Second archive listing for borg diff
if [[ ${COMP_LINE} =~ ^.*\ diff\ .*::[^\ ]+\ ${cur}$ ]] ; then
repository_name=`expr match "${COMP_LINE}" "\(.*\)::"`
repository_name=${repository_name##* }
typed_word=${cur}
fi
if [[ ${repository_name} != "" ]] ; then if [[ ${repository_name} != "" ]] ; then
if [[ ${COMP_LINE} == *" ::"* ]] ; then if [[ ${COMP_LINE} == *" ::"* ]] ; then
# There is a space before the "::" # There is a space before the "::"

View file

@ -337,3 +337,17 @@ function __fish_borg_list_archives
end end
complete -c borg -f -n __fish_borg_is_repository -a '(__fish_borg_list_archives)' complete -c borg -f -n __fish_borg_is_repository -a '(__fish_borg_list_archives)'
# Second archive listing for borg diff
function __fish_borg_is_diff_second_archive
return (string match --quiet --regex ' diff .*::[^ ]+ '(commandline --current-token)'$' (commandline))
end
function __fish_borg_list_diff_archives
set -l repository_name (string match --regex '[^ ]*::' (commandline))
set -l repository_name (string replace '::' '' $repository_name)
borg list --format="{archive}{NEWLINE}" "$repository_name" ^/dev/null
end
complete -c borg -f -n __fish_borg_is_diff_second_archive -a '(__fish_borg_list_diff_archives)'

View file

@ -172,7 +172,7 @@ _borg() {
(diff) (diff)
_arguments \ _arguments \
'2:archives:__borg_archive'\ '2:archives:__borg_archive'\
'3:archives:__borg_archive'\ '3:archives:__borg_archive2'\
'*:path:_files'\ '*:path:_files'\
--numeric-owner'[only obey numeric user and group identifiers]'\ --numeric-owner'[only obey numeric user and group identifiers]'\
--same-chunker-params'[override check of chunker parameters.]'\ --same-chunker-params'[override check of chunker parameters.]'\
@ -411,15 +411,26 @@ _borg() {
} }
__borg_archive() { __borg_archive() {
__borg_list_archives 1
}
__borg_archive2() {
__borg_list_archives 2
}
__borg_list_archives() {
local -a items local -a items
if (($+BORG_REPO)); then
items=("${(@f)$(borg list $cpath --short 2>/dev/null | sed "s#^#::#")}")
else
local cpath local cpath
cpath=$words[-1] cpath=`expr match "${words}" "\(.*\)::"`
cpath=${cpath%::*} cpath=${cpath##* }
items=("${(@f)$(borg list $cpath --short 2>/dev/null | sed "s#^#${cpath}::#")}") if (( $1 == 1 )); then
# To achieve "repository::archive" listing:
prefix_repo="${cpath}::"
fi fi
if (( $1 == 2 )); then
# To achieve only "archive" listing:
prefix_repo=
fi
items=("${(@f)$(borg list --format=$prefix_repo\{archive\}\{NEWLINE\} $cpath 2>/dev/null)}")
if [[ $items[1] == "" ]]; then if [[ $items[1] == "" ]]; then
_files -/ _files -/
else else