Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Transformed captured output $func() #5385

Closed
anki-code opened this issue May 2, 2024 · 1 comment
Closed

Feature: Transformed captured output $func() #5385

anki-code opened this issue May 2, 2024 · 1 comment

Comments

@anki-code
Copy link
Member

anki-code commented May 2, 2024

After merging #5377 I remember about old proposal. I'm not remember the author but It's interesting idea.

It will be cool to have an ability to create transformer of captured output:

json = $json(curl https://myjsonapi)  # python mode, returns json object

def mytransformer(stdout):
    # my transformations
    return stdout

my = $mytransformer(echo 123)  # python mode

echo $mytransformer(echo 123) | grep 1  # subprocess mode

For community

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

@anki-code anki-code changed the title feat: Transformed captured output $func() Feature: Transformed captured output $func() May 2, 2024
@anki-code
Copy link
Member Author

anki-code commented May 19, 2024

It's already implemented as xonsh macro:

def from_json(cmd):
    import json
    return json.loads(evalx(f"$({cmd})"))

o = from_json!(echo '{"a":1}')

o
#{'a': 1}
type(o)
# dict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant