From 6629f40cab1188c9ef229d445248bb4db1c9f804 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 28 May 2022 15:27:11 -0700 Subject: [PATCH] In bash completion script, warn when script is out of date using script contents instead of version. (Fewer spurious warnings that way.) --- borgmatic/commands/completion.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/borgmatic/commands/completion.py b/borgmatic/commands/completion.py index 623923299..0755be0e1 100644 --- a/borgmatic/commands/completion.py +++ b/borgmatic/commands/completion.py @@ -1,5 +1,3 @@ -import pkg_resources - from borgmatic.commands import arguments UPGRADE_MESSAGE = ''' @@ -28,15 +26,15 @@ def bash_completion(): top_level_parser, subparsers = arguments.make_parsers() global_flags = parser_flags(top_level_parser) actions = ' '.join(subparsers.choices.keys()) - borgmatic_version = pkg_resources.require('borgmatic')[0].version # Avert your eyes. return '\n'.join( ( + 'set -euo pipefail', 'check_version() {', - ' local installed_version="$(borgmatic --version 2> /dev/null)"', - ' if [ "$installed_version" != "%s" ] && [ "$installed_version" != "" ];' - % borgmatic_version, + ' local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"', + ' local installed_script="$(borgmatic --bash-completion 2> /dev/null)"', + ' if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];' ' then cat << EOF\n%s\nEOF' % UPGRADE_MESSAGE, ' fi', '}',