aliases: fix expand_alias (#5598)

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andy Kipp 2024-07-13 14:55:46 +02:00 committed by GitHub
parent 03499cb263
commit 38e9397f38
Failed to generate hash of commit
2 changed files with 11 additions and 1 deletions

View file

@ -107,6 +107,16 @@ def test_recursive_callable_partial_handles(xession):
assert obs == exp
def test_expand_alias():
ales = Aliases()
ales["ls"] = ["ls", "-G"]
ales["ff"] = lambda args: print(args)
exp_ls = ales.expand_alias("ls ", 3)
exp_ff = ales.expand_alias("ff ", 3)
assert exp_ls == "ls -G "
assert exp_ff == "ff "
def _return_to_sender_none():
return "wakka", {}

View file

@ -277,7 +277,7 @@ class Aliases(cabc.MutableMapping):
The command won't be expanded if the cursor's inside/behind it.
"""
word = (line.split(maxsplit=1) or [""])[0]
if word in XSH.aliases and isinstance(self.get(word), cabc.Sequence): # type: ignore
if word in self and not callable(self.get(word)[0]): # type: ignore
word_idx = line.find(word)
word_edge = word_idx + len(word)
if cursor_index > word_edge: