Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias completion #8053

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Comment on lines +93 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should only need one dict lookup here, something like:

Suggested change
cmdname = before_cursor[0]
if before_cursor[0] in config.cache['aliases']:
cmdname = config.cache['aliases'][before_cursor[0]].split(
maxsplit=1)[0]
cmdname = before_cursor[0]
alias = config.cache['aliases'].get(cmdname)
if alias:
cmdname = alias.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', '', []),
(':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
Loading