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

What about leading and trailing whitespace around the $() operator? #2

Open
anki-code opened this issue Oct 31, 2020 · 3 comments
Open
Labels

Comments

@anki-code
Copy link
Owner

The original question from laloch:

What about leading and trailing whitespace around the $() operator? Can you do mkdir -p /tmp/$(whoami)/garbage?

@anki-code
Copy link
Owner Author

anki-code commented Oct 31, 2020

Hi @laloch! Thank you for the great question!

Can you do mkdir -p /tmp/$(whoami)/garbage?

At this time in xonsh 0.9.24 this example is not working and I've tested the @() operator behavior:

echo 123@('456')
#123456

echo 123@(['456','789'])
# 123456 123789

Python substitution operator expands the prefix and duplicate it. This behavior looks good IMHO.

What about $() and XEP-2 proposal?

If we install xep-2 fork and try the similar example we can found that XEP-2 logic improves the behavior comparing with current xonsh:

mkdir -p /tmp/dir_test && cd /tmp/dir_test

# xonsh
mkdir -p here/@($(whoami))/garbage
tree here
#here
#└── pc\012
#    └── garbage

# 🔴 Unwanted 'pc'$'\n' directory.
# xonsh-xep-2
# pip install -U git+https://github.com/anki-code/xonsh-xep-2
rm -rf here
mkdir -p here/@($(whoami))/garbage
tree here
#here
#└── pc
#    └── garbage

# 🟢 Everything as expected.

As result my answer at this time will be: mkdir -p /tmp/$(whoami)/garbage should do the same as mkdir -p /tmp/@($(whoami))/garbage along with XEP-2 where $() is iterable object.

Does it make sense?

@daniel-shimon
Copy link

Maybe this should be part of the XEP? (make /tmp/$(whoami)/garbage expand like /tmp/@($(whoami))/garbage)

@anki-code
Copy link
Owner Author

anki-code commented Nov 2, 2020

Yeah, I think it will be good.
I'm waiting here for @laloch feedback as from author of the question. If it works for him I'll be happy to add the suggestion to the XEP-2.

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

No branches or pull requests

2 participants