Shell completions for borg diff second archive

This commit is contained in:
SanskritFritz 2019-03-15 17:40:47 +01:00
parent f20e6d751f
commit 8437972bc0
3 changed files with 39 additions and 8 deletions

View File

@ -156,6 +156,12 @@ _borg()
repository_name=${prevprev}
typed_word=${cur}
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 [[ ${COMP_LINE} == *" ::"* ]] ; then
# There is a space before the "::"

View File

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