Skip to content

Conversation

@Kissaki
Copy link
Contributor

@Kissaki Kissaki commented Nov 17, 2024

Add if defined expression via scope variables

Add if defined expression via `scope variables`
@fdncred fdncred merged commit 44c487c into nushell:main Nov 17, 2024
2 checks passed
@fdncred
Copy link
Contributor

fdncred commented Nov 17, 2024

Thanks

@NotTheDr01ds
Copy link
Contributor

How about?

if '$<variable>' in (scope variables).name { <command> }

@Kissaki
Copy link
Contributor Author

Kissaki commented Nov 18, 2024

@NotTheDr01ds I see. Not having to define a closure arguably means simpler syntax.

I wasn't aware in could be used like that, with a list-collect+path-get.

I was thinking about potential performance differences as well, but it seems like (scope variables).name would or could be streaming data in the same way.

Overall, I don't think there's a clear winner. They're alternative query approaches. Makes me wonder if adding both alternatives would make sense.

@fdncred
Copy link
Contributor

fdncred commented Nov 18, 2024

I do think this is more nushell idiomatic. This example should probably be updated.

'$rn' in (scope variables).name

Kissaki added a commit to Kissaki/nushell.github.io that referenced this pull request Nov 18, 2024
Follow-up to nushell#1637 as per discussion
@Kissaki
Copy link
Contributor Author

Kissaki commented Nov 18, 2024

I created #1643 for it.

fdncred pushed a commit that referenced this pull request Nov 18, 2024
Follow-up to #1637 as per discussion
@Kissaki Kissaki deleted the docs/cmd-ifdefined branch April 12, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants