Skip to content

Commit

Permalink
Add alias completion
Browse files Browse the repository at this point in the history
Partially fixes #32.
  • Loading branch information
knezi committed Jan 11, 2024
1 parent b490f28 commit c2041b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qutebrowser/completion/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def _get_new_completion(self, before_cursor, under_cursor):
log.completion.debug('Starting command completion')
return miscmodels.command
try:
cmd = objects.commands[before_cursor[0]]
cmdname = before_cursor[0]
if before_cursor[0] in config.cache['aliases']:
cmdname = config.cache['aliases'][before_cursor[0]].split(
maxsplit=1)[0]

cmd = objects.commands[cmdname]
except KeyError:
log.completion.debug("No completion for unknown command: {}"
.format(before_cursor[0]))
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/completion/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,18 @@ def _set_cmd_prompt(cmd, txt):
(':config-cycle option |', 'value', '', ['option']),
(':config-cycle option one |', 'value', '', ['option', 'one']),
(':config-cycle option one two |', 'value', '', ['option', 'one', 'two']),
(':openalias |', 'url', '', []),

Check warning on line 192 in tests/unit/completion/test_completer.py

View workflow job for this annotation

GitHub Actions / linters (flake8)

continuation line unaligned for hanging indent
(':bindalias |', None, '', []),
(':bindalias <c-x> |', 'command', '', ['<c-x>']),
(':bindalias <c-x> foo|', 'command', 'foo', ['<c-x>']),
(':bindalias <c-x>| foo', None, '<c-x>', []),
])
def test_update_completion(txt, kind, pattern, pos_args, status_command_stub,
completer_obj, completion_widget_stub, config_stub,
key_config_stub):
"""Test setting the completion widget's model based on command text."""
# this test uses | as a placeholder for the current cursor position
config_stub.val.aliases = {"bindalias": "bind", "openalias": "open -t"}
_set_cmd_prompt(status_command_stub, txt)
completer_obj.schedule_completion_update()
if kind is None:
Expand Down

0 comments on commit c2041b7

Please sign in to comment.