diff --git a/src/borg/archiver/completion_cmd.py b/src/borg/archiver/completion_cmd.py index 7eb101583..f0d40a693 100644 --- a/src/borg/archiver/completion_cmd.py +++ b/src/borg/archiver/completion_cmd.py @@ -18,7 +18,7 @@ from ..manifest import AI_HUMAN_SORT_KEYS # generated completion script for supported shells. # # Notes / constraints (per plan): -# - Calls `borg repo-list --format ...` and filters results by the typed aid: hex prefix. +# - Calls `borg repo-list --format ...` and filters results by the typed prefix (archive name or aid: hex). # - Non-interactive only. We rely on Borg to fail fast without prompting in non-interactive contexts. # If it cannot, we simply return no suggestions. @@ -33,14 +33,8 @@ BASH_PREAMBLE_TMPL = r""" if [[ ${COMP_WORDBREAKS-} == *:* ]]; then COMP_WORDBREAKS=${COMP_WORDBREAKS//:}; fi if [[ ${COMP_WORDBREAKS-} == *=* ]]; then COMP_WORDBREAKS=${COMP_WORDBREAKS//=}; fi -# Complete aid: archive IDs by querying "borg repo-list --short" -# Note: we only suggest the first 8 hex digits (short ID) for completion. -_borg_complete_aid() { +_borg_complete_archive() { local cur="${COMP_WORDS[COMP_CWORD]}" - [[ "$cur" == aid:* ]] || return 0 - - local prefix="${cur#aid:}" - [[ -n "$prefix" && ! "$prefix" =~ ^[0-9a-fA-F]*$ ]] && return 0 # derive repo context from words: --repo=V, --repo V, -r=V, -rV, or -r V local repo_arg=() @@ -56,24 +50,46 @@ _borg_complete_aid() { fi done - # ask borg for raw IDs; avoid prompts and suppress stderr - local out - if [[ -n "${repo_arg[*]}" ]]; then - out=$( borg repo-list "${repo_arg[@]}" --short 2>/dev/null /dev/null /dev/null /dev/null /dev/null /dev/null archive IDs by querying "borg repo-list --short" -# Note: we only suggest the first 8 hex digits (short ID) for completion. -_borg_complete_aid() { +_borg_complete_archive() { local cur cur="${words[$CURRENT]}" - [[ "$cur" == aid:* ]] || return 0 - - local prefix="${cur#aid:}" - # allow only hex digits as prefix; empty prefix also allowed (list all) - [[ -n "$prefix" && ! "$prefix" == [0-9a-fA-F]# ]] && return 0 # derive repo context from words: --repo=V, --repo V, -r=V, -rV, or -r V local -a repo_arg=() @@ -238,28 +247,55 @@ _borg_complete_aid() { fi done - # ask borg for raw IDs; avoid prompts and suppress stderr - local out - if (( ${#repo_arg[@]} > 0 )); then - out=$( borg repo-list "${repo_arg[@]}" --short 2>/dev/null /dev/null 0 )); then + out=$( borg repo-list "${repo_arg[@]}" --format '{id}{NL}' 2>/dev/null /dev/null 0 )); then + out=$( borg repo-list "${repo_arg[@]}" --format '{archive}{NL}' 2>/dev/null /dev/null