xonsh / xonsh

:shell: Python-powered shell. Full-featured and cross-platform.
http://xon.sh
Other
8.16k stars 633 forks source link

Windows: support windows env vars with () in their names: #2466

Open santagada opened 6 years ago

santagada commented 6 years ago

Right now xonsh doesn't support env variables with ( in their names.

$ProgramFiles(x86)                                                                                                                                                                                                                      
Traceback (most recent call last):
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\built_ins.py", line 512, in _run_binary
    p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\proc.py", line 558, in __init__
    **kwargs)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\__main__.py", line 2, in <module>
    main()
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\main.py", line 341, in main
    _failback_to_other_shells(args, err)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\main.py", line 305, in _failback_to_other_shells
    raise err
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\main.py", line 339, in main
    return main_xonsh(args)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\main.py", line 371, in main_xonsh
    run_code_with_cache(args.command.lstrip(), shell.execer, mode='single')
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\codecache.py", line 209, in run_code_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\codecache.py", line 68, in run_compiled_code
    func(code, glb, loc)
  File "8a9da7865483c5fd359f3acef178d26d", line 1, in <module>
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\built_ins.py", line 877, in subproc_captured_hiddenobject
    return run_subproc(cmds, captured='hiddenobject')
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\built_ins.py", line 813, in run_subproc
    command = HiddenCommandPipeline(specs)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\proc.py", line 1764, in __init__
    proc = spec.run(pipeline_group=pipeline_group)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\built_ins.py", line 502, in run
    p = self._run_binary(kwargs)
  File "C:\Users\leonardo.santagada\AppData\Local\Programs\Python\Python36\lib\site-packages\xonsh\built_ins.py", line 523, in _run_binary
    raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: x86
Did you mean the following?
    xip:  Alias

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

melund commented 6 years ago

I don't think this is fixable, Since the variables should also behave as normal python variables.

melund commented 6 years ago

However, there is a workaround with the ${} syntax.

snail@sea ~
$ ${'ProgramFiles(x86)'}
'C:\\Program Files (x86)'
melund commented 6 years ago

Ok. It probably shouldn't crash with that traceback. For me it shows the full traceback even if $XONSH_SHOW_TRACEBACK=False

melund commented 6 years ago

I have opened a separate issue for the last problem #2467

anki-code commented 1 month ago

I think it's possible to implement. As mentioned above this is working pretty well:

${'ProgramFiles(x86)'} = 1
${'ProgramFiles(x86)'}
# 1

It's needed to fix the completion:

$P<Tab>
$ProgramFiles(x86)  # instead of ${'ProgramFiles(x86)'}

Use this PR to fix completion - https://github.com/xonsh/xonsh/pull/5388