浏览代码

In bash completion script, warn when script is out of date using script contents instead of version. (Fewer spurious warnings that way.)

Dan Helfman 3 年之前
父节点
当前提交
6629f40cab
共有 1 个文件被更改,包括 4 次插入6 次删除
  1. 4 6
      borgmatic/commands/completion.py

+ 4 - 6
borgmatic/commands/completion.py

@@ -1,5 +1,3 @@
-import pkg_resources
-
 from borgmatic.commands import arguments
 from borgmatic.commands import arguments
 
 
 UPGRADE_MESSAGE = '''
 UPGRADE_MESSAGE = '''
@@ -28,15 +26,15 @@ def bash_completion():
     top_level_parser, subparsers = arguments.make_parsers()
     top_level_parser, subparsers = arguments.make_parsers()
     global_flags = parser_flags(top_level_parser)
     global_flags = parser_flags(top_level_parser)
     actions = ' '.join(subparsers.choices.keys())
     actions = ' '.join(subparsers.choices.keys())
-    borgmatic_version = pkg_resources.require('borgmatic')[0].version
 
 
     # Avert your eyes.
     # Avert your eyes.
     return '\n'.join(
     return '\n'.join(
         (
         (
+            'set -euo pipefail',
             'check_version() {',
             '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,
             '        then cat << EOF\n%s\nEOF' % UPGRADE_MESSAGE,
             '    fi',
             '    fi',
             '}',
             '}',