mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
![]() ### Motivation
* To have an ability to manage the output format added ``$XONSH_SUBPROC_OUTPUT_FORMAT`` to switch the way to return the output lines. Default ``stream_lines`` to return text. Alternative ``list_lines`` to return the list of lines. Also supported custom lambda function.
* Additionally the [proposal to change default behavior](https://github.com/xonsh/xonsh/pull/5377#discussion_r1587627131) for a single line case.
* Closes #3924 as soft solution.
### Before
```xsh
mkdir -p /tmp/tst && cd /tmp/tst && touch 1 2 3
$(ls)
# '1\n2\n3\n'
id $(whoami)
# id: ‘pc\n’: no such user: Invalid argument
du $(ls)
# du: cannot access '1'$'\n''2'$'\n''3'$'\n': No such file or directory
ls $(fzf)
# ls: cannot access 'FUNDING.yml'$'\n': No such file or directory
```
### After
```xsh
mkdir -p /tmp/tst && cd /tmp/tst && touch 1 2 3
$XONSH_SUBPROC_OUTPUT_FORMAT = 'list_lines'
$(ls)
# ['1', '2', '3']
[f for f in $(ls)]
# ['1', '2', '3']
id $(whoami)
# uid=501(user) gid=20(staff)
du $(ls)
# 0 1
# 0 2
# 0 3
ls $(fzf)
# FUNDING.yml
# etc
mkdir -p /tmp/@($(whoami))/dir
cat /etc/passwd | grep $(whoami)
```
### Notes
* It will be good to improve parser for cases like `mkdir -p /tmp/$(whoami)/dir`. PR is welcome!
* I named the default mode as `stream_lines` (instead of just `stream` or `raw`) because in fact we transform raw output into stream of lines and possibly reduce the length of output ([replacing `\r\n` to `\n`](
|
||
---|---|---|
.. | ||
_static | ||
_templates | ||
api | ||
extensions | ||
advanced_events.rst | ||
aliases.rst | ||
appimage.rst | ||
bash_to_xsh.rst | ||
changelog.rst | ||
comparison.rst | ||
conf.py | ||
contact.rst | ||
containers.rst | ||
contents.rst | ||
contributing.rst | ||
customization.rst | ||
development.rst | ||
devguide.rst | ||
editors.rst | ||
envvars.rst.jinja2 | ||
events.rst | ||
faq.rst | ||
guides.rst | ||
installation.rst | ||
intro.rst | ||
keyboard_shortcuts.rst | ||
links.rst | ||
Makefile | ||
packages.rst | ||
platform-issues.rst | ||
python-versions-support-policy.rst | ||
python_virtual_environments.rst | ||
quotes.rst | ||
serve_docs.py | ||
setup.rst | ||
subproc_types.rst | ||
talks_and_articles.rst | ||
todo.rst | ||
tryitnow.rst | ||
tutorial.rst | ||
tutorial_completers.rst | ||
tutorial_events.rst | ||
tutorial_hist.rst | ||
tutorial_history_backend.rst | ||
tutorial_macros.rst | ||
tutorial_ptk.rst | ||
tutorial_subproc_strings.rst | ||
tutorial_xonsh_projects.rst | ||
tutorial_xontrib.rst | ||
xonshconfig.json | ||
xonshrc.py | ||
xonshrc.rst | ||
xonshrc.xsh |