From e909231d76cd5a4ad1b6f28f577e59d00483a431 Mon Sep 17 00:00:00 2001
From: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
Date: Thu, 23 Dec 2021 12:26:56 +0100
Subject: Add support for bash autocompletion via argcomplete, if installed.

---
 CHANGELOG.rst     | 1 +
 lesana/command.py | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index feec380..c01bd47 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -19,6 +19,7 @@ Unreleased
   entries, while ``lesana search`` with no other options will list the
   first 12 entries (possibly according to a default sorting setting).
 * New collection example: ticket_tracker.
+* Add support for bash autocompletion via argcomplete, if installed.
 
 Bugfixes
 --------
diff --git a/lesana/command.py b/lesana/command.py
index 4c723af..6914ca3 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -4,6 +4,11 @@ import os
 import subprocess
 import sys
 
+try:
+    import argcomplete
+except ImportError as e:
+    argcomplete = False
+
 from . import Collection, Entry, TemplatingError
 
 logger = logging.getLogger(__name__)
@@ -40,6 +45,8 @@ class MainCommand:
             for arg in sub.arguments:
                 s_parser.add_argument(*arg[0], **arg[1])
             s_parser.set_defaults(func=sub._main)
+        if argcomplete:
+            argcomplete.autocomplete(self.parser)
         self.args = self.parser.parse_args()
 
         if self.args.verbose:
-- 
cgit v1.2.3