summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSanskritFritz <SanskritFritz+github@gmail.com>2021-01-30 13:16:27 +0100
committerSanskritFritz <SanskritFritz+github@gmail.com>2021-01-30 13:16:27 +0100
commit426fb9e8ec2348908d0523b829bc14c2b2504bd4 (patch)
tree3d7a598407947f59b5e6162c12a1e2fe001e0d54 /scripts
parent4346c4e85b05be47df64405c90ec4353320d96f7 (diff)
Efficiency fixes thanks to @oxiedi
Diffstat (limited to 'scripts')
-rw-r--r--scripts/shell_completions/bash/borg24
1 files changed, 11 insertions, 13 deletions
diff --git a/scripts/shell_completions/bash/borg b/scripts/shell_completions/bash/borg
index 0bca21b5e..1262f2e1a 100644
--- a/scripts/shell_completions/bash/borg
+++ b/scripts/shell_completions/bash/borg
@@ -146,35 +146,33 @@ _borg()
# 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=`expr match "${COMP_LINE}" "\(.*\)::"`
+ local repository_name="${COMP_LINE%%::*}"
repository_name=${repository_name##* }
# Listing archives.
# Since "::" is treated as separate word in Bash,
# it is $cur when the cursor is right behind it
# and $prev if the user has started to type an archive name.
- local typed_word=""
- local please_list_the_archives=false
+ local typed_word=${cur}
+ local -i list_archives=0
if [[ ${cur} == "::" ]] ; then
- please_list_the_archives=true
+ list_archives=1
+ typed_word=""
fi
if [[ ${prev} == "::" ]] ; then
- please_list_the_archives=true
- typed_word=${cur}
+ list_archives=1
fi
# Second archive listing for borg diff
if [[ ${COMP_LINE} =~ ^.*\ diff\ .*::[^\ ]+\ ${cur}$ ]] ; then
- please_list_the_archives=true
- typed_word=${cur}
+ list_archives=1
fi
# Additional archive listing for borg delete
if [[ ${COMP_LINE} =~ ^.*\ delete\ .*::[^\ ]+.*${cur}$ ]] ; then
- please_list_the_archives=true
- typed_word=${cur}
+ list_archives=1
fi
- if [[ $please_list_the_archives = true ]] ; then
- local archive_list=$(borg list --short "${repository_name}" 2>/dev/null)
- COMPREPLY=( $(compgen -W "${archive_list}" -- "${typed_word}" ) )
+ if (( $list_archives )) ; then
+ local archives=$(borg list --short "${repository_name}" 2>/dev/null)
+ COMPREPLY=( $(compgen -W "${archives}" -- "${typed_word}" ) )
return 0
fi