mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Merge pull request #3677 from daniel-shimon/exec-aliases-on-io-operators
Create ExecAlias for aliases that contain IO operators
This commit is contained in:
commit
1ee8e38fba
3 changed files with 44 additions and 4 deletions
23
news/exec-aliases-on-io-operators.rst
Normal file
23
news/exec-aliases-on-io-operators.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Setting an alias with IO redirections (e.g ``ls | wc``) now works correctly.
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -128,3 +128,20 @@ def test_subprocess_logical_operators(xonsh_execer, xonsh_builtins, alias):
|
|||
ales = make_aliases()
|
||||
ales["echocat"] = alias
|
||||
assert isinstance(ales["echocat"], ExecAlias)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"alias",
|
||||
[
|
||||
"echo 'hi' | grep h",
|
||||
"echo 'hi' > file",
|
||||
"cat < file",
|
||||
"COMMAND1 e>o < input.txt | COMMAND2 > output.txt e>> errors.txt",
|
||||
"echo 'h|i' | grep h",
|
||||
"echo 'h|i << x > 3' | grep x",
|
||||
],
|
||||
)
|
||||
def test_subprocess_io_operators(xonsh_execer, xonsh_builtins, alias):
|
||||
ales = make_aliases()
|
||||
ales["echocat"] = alias
|
||||
assert isinstance(ales["echocat"], ExecAlias)
|
||||
|
|
|
@ -48,8 +48,8 @@ if ON_POSIX:
|
|||
|
||||
|
||||
@lazyobject
|
||||
def SUB_EXEC_ALIAS_RE():
|
||||
return re.compile(r"@\(|\$\(|!\(|\$\[|!\[|\&\&|\|\||\s+and\s+|\s+or\s+")
|
||||
def EXEC_ALIAS_RE():
|
||||
return re.compile(r"@\(|\$\(|!\(|\$\[|!\[|\&\&|\|\||\s+and\s+|\s+or\s+|[>|<]")
|
||||
|
||||
|
||||
class Aliases(cabc.MutableMapping):
|
||||
|
@ -128,8 +128,8 @@ class Aliases(cabc.MutableMapping):
|
|||
def __setitem__(self, key, val):
|
||||
if isinstance(val, str):
|
||||
f = "<exec-alias:" + key + ">"
|
||||
if SUB_EXEC_ALIAS_RE.search(val) is not None:
|
||||
# We have a sub-command, e.g. $(cmd), to evaluate
|
||||
if EXEC_ALIAS_RE.search(val) is not None:
|
||||
# We have a sub-command (e.g. $(cmd)) or IO redirect (e.g. >>)
|
||||
self._raw[key] = ExecAlias(val, filename=f)
|
||||
elif isexpression(val):
|
||||
# expansion substitution
|
||||
|
|
Loading…
Add table
Reference in a new issue