Xonsh: How can you use bracket

Created on 31 Mar 2020  路  3Comments  路  Source: xonsh/xonsh

I'm trying to exclude multiple directories from the following grep statement

grep -Ril approval-approved ./ --exclude-dir={vendor,storage}

imagen

xonfig

| title | details |
|------------------|----------------------|
| xonsh | 0.9.13.dev1 |
| Git SHA | 9f7ccc65 |
| Commit Date | Oct 15 17:14:50 2019 |
| Python | 3.7.3 |
| PLY | 3.11 |
| have readline | True |
| prompt toolkit | 3.0.2 |
| shell type | prompt_toolkit2 |
| pygments | 2.5.2 |
| on posix | True |
| on linux | True |
| distro | ubuntu |
| on darwin | False |
| on windows | False |
| on cygwin | False |
| on msys2 | False |
| is superuser | False |
| default encoding | utf-8 |
| xonsh encoding | utf-8 |
| encoding errors | surrogateescape |

$ xonfig

Expected Behavior

Exclude multiple directories when executing grep

Current Behavior

Confused with brackets for environment variables

Traceback (if applicable)

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/xonsh/ptk2/shell.py", line 180, in _push
    code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/__amalgam__.py", line 23101, in compile
    tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/__amalgam__.py", line 23061, in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/__amalgam__.py", line 23201, in _parse_ctx_free
    raise original_error from None
  File "/usr/local/lib/python3.7/dist-packages/xonsh/__amalgam__.py", line 23186, in _parse_ctx_free
    debug_level=(self.debug_level > 2),
  File "/usr/local/lib/python3.7/dist-packages/xonsh/parsers/base.py", line 543, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/ply/ply/yacc.py", line 335, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/ply/ply/yacc.py", line 1203, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/ply/ply/yacc.py", line 194, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.7/dist-packages/xonsh/parsers/base.py", line 3399, in p_error
    self._parse_error(msg, self.currloc(lineno=p.lineno, column=p.lexpos))
  File "/usr/local/lib/python3.7/dist-packages/xonsh/parsers/base.py", line 676, in _parse_error
    raise err
  File "<string>", line None
SyntaxError: <xonsh-code>:1:10: ('code: approval',)
grep -Ril approval-approved ./ --exclude-dir={vendor,storage}
          ^

Steps to Reproduce

execute command
grep -Ril approval-approved ./ --exclude-dir={vendor,storage}

question

Most helpful comment

Hi @ErickTucto, unfortunately Xonsh cannot do brace expansion (yet). You can, however, achieve similar effect using @() operator. See Python Evaluation with @() tutorial chapter for details.
Your command using @() would look like:

grep -Ril approval-approved ./ --exclude-dir=@(['vendor','storage'])

All 3 comments

Hi @ErickTucto, unfortunately Xonsh cannot do brace expansion (yet). You can, however, achieve similar effect using @() operator. See Python Evaluation with @() tutorial chapter for details.
Your command using @() would look like:

grep -Ril approval-approved ./ --exclude-dir=@(['vendor','storage'])

PRs are very welcome for brace expansion, too!

Thanks @laloch for the command

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sucrecacao picture sucrecacao  路  5Comments

sergiopr89 picture sergiopr89  路  5Comments

OJFord picture OJFord  路  6Comments

CJ-Wright picture CJ-Wright  路  5Comments

74th picture 74th  路  4Comments