diff --git a/src/borg/archiver/completion_cmd.py b/src/borg/archiver/completion_cmd.py index 6a39c8f79d..c50287735d 100644 --- a/src/borg/archiver/completion_cmd.py +++ b/src/borg/archiver/completion_cmd.py @@ -16,6 +16,7 @@ - Completes archive names by default (e.g., "my-backup-2024") - Completes archive IDs when prefixed with "aid:" (e.g., "aid:12345678") - In zsh and fish, shows archive metadata (name, timestamp, user@host) as descriptions + (tcsh has no completion descriptions) - Respects --repo/-r flags to query the correct repository 2. Sort keys (SortBySpec): @@ -54,6 +55,8 @@ - Suggests common file size values (500M, 1G, 10G, 100G, 1T, etc.) """ +import re + import shtab from ._common import process_epilog @@ -790,6 +793,103 @@ """ +TCSH_PREAMBLE_TMPL = r""" +# Dynamic completion helpers for tcsh + +alias _borg_complete_timestamp 'date +"%Y-%m-%dT%H:%M:%S"' + + +alias _borg_complete_sortby "echo {SORT_KEYS}" +alias _borg_complete_filescachemode "echo {FCM_KEYS}" +alias _borg_help_topics "echo {HELP_CHOICES}" +alias _borg_complete_compression_spec "echo {COMP_SPEC_CHOICES}" +alias _borg_complete_chunker_params "echo {CHUNKER_PARAMS_CHOICES}" +alias _borg_complete_relative_time "echo {RELATIVE_TIME_CHOICES}" +alias _borg_complete_file_size "echo {FILE_SIZE_CHOICES}" + +# Complete archive names (archive IDs when the current token starts with "aid:") and tags. +# These need the command line (for --repo/-r) and some logic, which tcsh cannot do itself: +# it has no functions, and an alias cannot use backquotes here because the completion rule +# calling the alias is backquoted already. So the work is done by a POSIX sh script, kept in +# a variable (a single-quoted csh string, hence no single quotes in it) and run via "sh -c". +set _borg_sh_complete = '{SH_COMPLETE}' + +alias _borg_complete_archive 'sh -c "$_borg_sh_complete" borg-completion archive "$COMMAND_LINE"' +alias _borg_complete_tags 'sh -c "$_borg_sh_complete" borg-completion tags "$COMMAND_LINE"' +""" + +# the sh script the tcsh preamble runs, as one line (`sh -c