From 97a971624bc0ac02b792f912779224caa9b03974 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 9 Aug 2016 07:24:17 -0400 Subject: [PATCH] Show bindings for aliases in completion. Command completions for `:bind` and `:` will now show bindings for aliases. The binding is only included if it is bound to that alias, not if it is bound to the command the alias points to. --- qutebrowser/completion/models/miscmodels.py | 3 ++- tests/unit/completion/test_models.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index cdf201a79..2ff98a195 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -283,6 +283,7 @@ def _get_cmd_completions(include_hidden, include_aliases, prefix=''): if include_aliases: for name, cmd in config.section('aliases').items(): - cmdlist.append((name, "Alias for '{}'".format(cmd), '')) + bindings = ', '.join(cmd_to_keys.get(name, [])) + cmdlist.append((name, "Alias for '{}'".format(cmd), bindings)) return sorted(cmdlist) diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 519bef60a..deb8c7179 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -173,7 +173,9 @@ def test_command_completion(qtmodeltester, monkeypatch, stubs, config_stub, _patch_cmdutils(monkeypatch, stubs, 'qutebrowser.completion.models.miscmodels.cmdutils') config_stub.data['aliases'] = {'rock': 'roll'} - key_config_stub.set_bindings_for('normal', {'s': 'stop', 'rr': 'roll'}) + key_config_stub.set_bindings_for('normal', {'s': 'stop', + 'rr': 'roll', + 'ro': 'rock'}) model = miscmodels.CommandCompletionModel() qtmodeltester.data_display_may_return_none = True qtmodeltester.check(model) @@ -182,7 +184,7 @@ def test_command_completion(qtmodeltester, monkeypatch, stubs, config_stub, assert actual == [ ("Commands", [ ('drop', 'drop all user data', ''), - ('rock', "Alias for 'roll'", ''), + ('rock', "Alias for 'roll'", 'ro'), ('roll', 'never gonna give you up', 'rr'), ('stop', 'stop qutebrowser', 's') ]) @@ -465,7 +467,9 @@ def test_bind_completion(qtmodeltester, monkeypatch, stubs, config_stub, _patch_cmdutils(monkeypatch, stubs, 'qutebrowser.completion.models.miscmodels.cmdutils') config_stub.data['aliases'] = {'rock': 'roll'} - key_config_stub.set_bindings_for('normal', {'s': 'stop', 'rr': 'roll'}) + key_config_stub.set_bindings_for('normal', {'s': 'stop', + 'rr': 'roll', + 'ro': 'rock'}) model = miscmodels.BindCompletionModel() qtmodeltester.data_display_may_return_none = True qtmodeltester.check(model) @@ -475,7 +479,7 @@ def test_bind_completion(qtmodeltester, monkeypatch, stubs, config_stub, ("Commands", [ ('drop', 'drop all user data', ''), ('hide', '', ''), - ('rock', "Alias for 'roll'", ''), + ('rock', "Alias for 'roll'", 'ro'), ('roll', 'never gonna give you up', 'rr'), ('stop', 'stop qutebrowser', 's') ])