xonsh/docs
Andy Kipp c5cb7044b5
feat: add subproc output format, autostrip singleline output (#5377)
### 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`](c3a12b2a9c/xonsh/procs/pipelines.py (L380-L383))). May be some day we need to add raw "stream" output format.
* Now anybody can implement bash `IFS` behavior in [bashisms](https://github.com/xonsh/xontrib-bashisms).

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-02 11:48:25 -04:00
..
_static Add files via upload 2023-05-19 23:01:11 +06:00
_templates Xonsh Zulip Community started (#5372) 2024-04-29 10:01:02 -04:00
api Pr5 xontrib entrypoints (#4827) 2022-06-17 12:39:12 -04:00
extensions feat: use github actions to deploy docs (#4641) 2022-01-18 11:38:27 -05:00
advanced_events.rst Pre commit ci (#4863) 2022-07-01 11:47:01 -04:00
aliases.rst Rm xontrib meta (#4790) 2022-05-04 15:02:20 -04:00
appimage.rst Pre commit ci (#4863) 2022-07-01 11:47:01 -04:00
bash_to_xsh.rst feat: add subproc output format, autostrip singleline output (#5377) 2024-05-02 11:48:25 -04:00
changelog.rst doc fixes 2017-02-22 11:49:45 -05:00
comparison.rst correct scandalous misrepresentation of the friendly interactive shell's feature set (#5235) 2023-11-27 11:12:28 +01:00
conf.py docs: change theme to furo (#4809) 2022-05-18 20:36:45 +05:30
contact.rst Xonsh Zulip Community started (#5372) 2024-04-29 10:01:02 -04:00
containers.rst consolidation 2020-10-09 01:54:42 +03:00
contents.rst adopt NEP-0029 (#4568) 2021-11-29 12:48:48 -05:00
contributing.rst Xonsh Zulip Community started (#5372) 2024-04-29 10:01:02 -04:00
customization.rst New prompt end character (#5063) 2023-05-16 13:36:50 +00:00
development.rst Greatly improved webpage layout so it is easier to find what you need. (#2477) 2017-08-13 21:48:26 -04:00
devguide.rst Added repl.it to the docs 2018-06-12 16:54:11 -04:00
editors.rst Mention VS Code supports xonsh as default shell (#5273) 2024-02-06 00:29:45 +01:00
envvars.rst.jinja2 feat: use github actions to deploy docs (#4641) 2022-01-18 11:38:27 -05:00
events.rst add generic on_pre_spec_run and on_post_spec_run (#5232) 2023-11-23 12:19:34 +01:00
faq.rst Add FAQ for adding context menu 2019-10-01 15:14:59 +09:00
guides.rst consolidation 2020-10-09 01:54:42 +03:00
installation.rst fix: docs building (#4820) 2022-05-30 20:49:38 +05:30
intro.rst Mention 3.6 instead of 3.5 in docs (#5193) 2023-08-23 21:30:20 +06:00
keyboard_shortcuts.rst docs: Remove highlight shortcuts 'beta' tag (#4403) 2021-08-16 11:42:34 -04:00
links.rst Updated references to point to 'main' instead of 'master' (#4202) 2021-03-30 13:40:43 -04:00
Makefile Pr5 xontrib entrypoints (#4827) 2022-06-17 12:39:12 -04:00
packages.rst Update packages.rst: fix link (#5196) 2023-09-04 13:51:20 +06:00
platform-issues.rst New prompt end character (#5063) 2023-05-16 13:36:50 +00:00
python-versions-support-policy.rst adopt NEP-0029 (#4568) 2021-11-29 12:48:48 -05:00
python_virtual_environments.rst New prompt end character (#5063) 2023-05-16 13:36:50 +00:00
quotes.rst no org 2016-12-20 15:20:03 -08:00
serve_docs.py Rm xontrib meta (#4790) 2022-05-04 15:02:20 -04:00
setup.rst Rm xontrib meta (#4790) 2022-05-04 15:02:20 -04:00
subproc_types.rst typo fixes 2018-04-04 14:45:28 -04:00
talks_and_articles.rst Update talks_and_articles.rst (#4140) 2021-03-05 10:15:39 -05:00
todo.rst Pre commit ci (#4863) 2022-07-01 11:47:01 -04:00
tryitnow.rst runthis 2020-03-19 23:05:18 -05:00
tutorial.rst feat: add subproc output format, autostrip singleline output (#5377) 2024-05-02 11:48:25 -04:00
tutorial_completers.rst Fix documented default loc parameter for add_one_completer() (#5289) 2024-02-27 16:22:12 +01:00
tutorial_events.rst Pre commit ci (#4863) 2022-07-01 11:47:01 -04:00
tutorial_hist.rst history pull (#5047) 2023-02-08 08:20:01 -05:00
tutorial_history_backend.rst New prompt end character (#5063) 2023-05-16 13:36:50 +00:00
tutorial_macros.rst a few more 2020-10-03 23:25:27 -04:00
tutorial_ptk.rst Pre commit ci (#4863) 2022-07-01 11:47:01 -04:00
tutorial_subproc_strings.rst fix: add M1 bash-completion path to osx defaults (#4740) 2022-03-28 21:43:11 +05:30
tutorial_xonsh_projects.rst spellcheck 2019-10-02 13:41:15 -04:00
tutorial_xontrib.rst Pr5 xontrib entrypoints (#4827) 2022-06-17 12:39:12 -04:00
xonshconfig.json more docs 2016-05-11 01:55:53 -04:00
xonshrc.py Lab/py control file (#4420) 2021-08-19 12:40:22 -04:00
xonshrc.rst New prompt end character (#5063) 2023-05-16 13:36:50 +00:00
xonshrc.xsh xonshrc.xsh now links to more details 2018-10-26 17:07:00 -04:00