From: Andrea Righi Date: Mon, 5 Dec 2022 16:48:39 +0000 (+0100) Subject: annotations: add an option to enable config autocompletion in bash X-Git-Tag: v0.1~46 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=7e0b8f1952db0c7882f15e08b2160f0a9f250dcb;p=annotations.git annotations: add an option to enable config autocompletion in bash Type `source <(annotations --autocomplete)` to enable auto-completion of config options (without the CONFIG_ prefix) in bash when running annotations script commands. Signed-off-by: Andrea Righi --- diff --git a/annotations b/annotations index 6b1a0a3..c74dbe7 100755 --- a/annotations +++ b/annotations @@ -37,6 +37,8 @@ def make_parser(): help='Query annotations') parser.add_argument('--note', '-n', action='store', help='Write a specific note to a config option in annotations') + parser.add_argument('--autocomplete', action='store_true', + help='Enable config bash autocomplete: `source <(annotations --autocomplete)`') ga = parser.add_argument_group(title='Action').add_mutually_exclusive_group(required=False) ga.add_argument('--write', '-w', action='store', @@ -77,6 +79,11 @@ def do_query(args): break print_result(config, res) +def do_autocomplete(args): + a = Annotation(args.file) + res = (c.removeprefix('CONFIG_') for c in a.search_config()) + print('complete -W "{}" annotations'.format(' '.join(res))) + def do_note(args): if args.config is None: arg_fail('error: --note requires --config') @@ -226,6 +233,8 @@ def main(): do_update(args) elif args.check_file: do_check(args) + elif args.autocomplete: + do_autocomplete(args) else: do_query(args)