mirror of https://github.com/borgbackup/borg.git
Merge pull request #5656 from SanskritFritz/master
Tab completion support for additional archives for 'borg delete'
This commit is contained in:
commit
6844d33e7f
|
@ -143,34 +143,36 @@ _borg()
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get the repository name if available
|
||||||
|
# If there is a space before the "::" it means that no repository name was typed,
|
||||||
|
# so probably $BORG_REPO was set and we can still list the archives.
|
||||||
|
local repository_name="${COMP_LINE%%::*}"
|
||||||
|
repository_name=${repository_name##* }
|
||||||
|
|
||||||
# Listing archives.
|
# Listing archives.
|
||||||
# Since "::" is treated as separate word in bash,
|
# Since "::" is treated as separate word in Bash,
|
||||||
# it is $cur when the cursor is right behind it
|
# it is $cur when the cursor is right behind it
|
||||||
# and $prev if the user has started to type an archive name.
|
# and $prev if the user has started to type an archive name.
|
||||||
local repository_name="" # If set, we'll list the archives
|
local typed_word=${cur}
|
||||||
local typed_word=""
|
local -i list_archives=0
|
||||||
if [[ ${cur} == "::" ]] ; then
|
if [[ ${cur} == "::" ]] ; then
|
||||||
repository_name=${prev}
|
list_archives=1
|
||||||
|
typed_word=""
|
||||||
fi
|
fi
|
||||||
if [[ ${prev} == "::" ]] ; then
|
if [[ ${prev} == "::" ]] ; then
|
||||||
repository_name=${prevprev}
|
list_archives=1
|
||||||
typed_word=${cur}
|
|
||||||
fi
|
fi
|
||||||
# Second archive listing for borg diff
|
# Second archive listing for borg diff
|
||||||
if [[ ${COMP_LINE} =~ ^.*\ diff\ .*::[^\ ]+\ ${cur}$ ]] ; then
|
if [[ ${COMP_LINE} =~ ^.*\ diff\ .*::[^\ ]+\ ${cur}$ ]] ; then
|
||||||
repository_name=`expr match "${COMP_LINE}" "\(.*\)::"`
|
list_archives=1
|
||||||
repository_name=${repository_name##* }
|
|
||||||
typed_word=${cur}
|
|
||||||
fi
|
fi
|
||||||
if [[ ${repository_name} != "" ]] ; then
|
# Additional archive listing for borg delete
|
||||||
if [[ ${COMP_LINE} == *" ::"* ]] ; then
|
if [[ ${COMP_LINE} =~ ^.*\ delete\ .*::[^\ ]+.*${cur}$ ]] ; then
|
||||||
# There is a space before the "::"
|
list_archives=1
|
||||||
# which means that no repository name was typed,
|
|
||||||
# so probably $BORG_REPO is set.
|
|
||||||
repository_name=""
|
|
||||||
fi
|
fi
|
||||||
local archive_list=$(borg list --short "${repository_name}" 2>/dev/null)
|
if (( $list_archives )) ; then
|
||||||
COMPREPLY=( $(compgen -W "${archive_list}" -- "${typed_word}" ) )
|
local archives=$(borg list --short "${repository_name}" 2>/dev/null)
|
||||||
|
COMPREPLY=( $(compgen -W "${archives}" -- "${typed_word}" ) )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -360,7 +360,7 @@ function __fish_borg_list_repos_or_archives
|
||||||
if string match --quiet --regex '.*::' '"'(commandline --current-token)'"'
|
if string match --quiet --regex '.*::' '"'(commandline --current-token)'"'
|
||||||
# If the current token contains "::" then list the archives:
|
# If the current token contains "::" then list the archives:
|
||||||
set -l repository_name (string replace --regex '::.*' '' (commandline --current-token))
|
set -l repository_name (string replace --regex '::.*' '' (commandline --current-token))
|
||||||
borg list --format="$repository_name::{archive}{NEWLINE}" "$repository_name" ^/dev/null
|
borg list --format="$repository_name::{archive}{TAB}{comment}{NEWLINE}" "$repository_name" ^/dev/null
|
||||||
else
|
else
|
||||||
# Otherwise list the repositories, directories and user@host entries:
|
# Otherwise list the repositories, directories and user@host entries:
|
||||||
set -l directories (commandline --cut-at-cursor --current-token)*/
|
set -l directories (commandline --cut-at-cursor --current-token)*/
|
||||||
|
@ -378,15 +378,20 @@ end
|
||||||
complete -c borg -f -n "__fish_borg_is_argument_n 2" -a '(__fish_borg_list_repos_or_archives)'
|
complete -c borg -f -n "__fish_borg_is_argument_n 2" -a '(__fish_borg_list_repos_or_archives)'
|
||||||
|
|
||||||
|
|
||||||
# Second archive listing for borg diff
|
# Additional archive listings
|
||||||
|
|
||||||
function __fish_borg_is_diff_second_archive
|
function __fish_borg_is_diff_second_archive
|
||||||
return (string match --quiet --regex ' diff .*::[^ ]+ '(commandline --current-token)'$' (commandline))
|
return (string match --quiet --regex ' diff .*::[^ ]+ '(commandline --current-token)'$' (commandline))
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_borg_list_diff_archives
|
function __fish_borg_is_delete_additional_archive
|
||||||
set -l repo_matches (string match --regex '([^ ]*)::' (commandline))
|
return (string match --quiet --regex ' delete .*::[^ ]+ ' (commandline))
|
||||||
borg list --format="{archive}{NEWLINE}" "$repo_matches[2]" ^/dev/null
|
|
||||||
end
|
end
|
||||||
|
|
||||||
complete -c borg -f -n __fish_borg_is_diff_second_archive -a '(__fish_borg_list_diff_archives)'
|
function __fish_borg_list_only_archives
|
||||||
|
set -l repo_matches (string match --regex '([^ ]*)::' (commandline))
|
||||||
|
borg list --format="{archive}{TAB}{comment}{NEWLINE}" "$repo_matches[2]" ^/dev/null
|
||||||
|
end
|
||||||
|
|
||||||
|
complete -c borg -f -n __fish_borg_is_diff_second_archive -a '(__fish_borg_list_only_archives)'
|
||||||
|
complete -c borg -f -n __fish_borg_is_delete_additional_archive -a '(__fish_borg_list_only_archives)'
|
||||||
|
|
Loading…
Reference in New Issue