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

Update shell redirections #399

Merged
merged 3 commits into from
Aug 28, 2022
Merged

Update shell redirections #399

merged 3 commits into from
Aug 28, 2022

Conversation

vinc
Copy link
Owner

@vinc vinc commented Aug 27, 2022

"Those who don't understand Unix are condemned to reinvent it, poorly."

I've been reading the doc I wrote about file handle redirections in the shell and they were associated with the thin arrow -> (pipes) instead of the fat arrow => (redirections).

While I was fixing that I noticed that I didn't have a use for a < shortcut because > was used for thin arrows instead of fat arrows. Fat arrows can be written in both directions, so it'd make more sens to have both shortcuts for them, like in Unix. And then | became really tempting as a shortcut for the thin arrow, like in Unix. I resisted that in the past, instead preferring to use it for the or-combinator. If I use the keyword or for the or-combinator (or even || as in Unix) then | is free for the pipe shortcut...

We'll see, but now > will stand for => and < for <=.

While I was doing that I also revisited the decision in #387 to have => appending to files, instead I made it truncate first as it was before and added =>> which can be shortened to >> ... like in Unix. It's really useful to have both append and truncate in one command instead of having to use delete first for the latter. I was missing it while I tested the feature.

In this PR I'm also adding a long syntax for file handles in redirections with the explicit [1]=> being equivalent to the implicit => while keeping the short 1=> that can now be even shorter with 1>, making it even shorter than in Unix. [1]=>[3] will also be possible in the future.

@vinc
Copy link
Owner Author

vinc commented Aug 27, 2022

All the following commands are equivalents:

> time read foo.txt --> write /dev/null
> time read foo.txt -> write /dev/null
> t r foo.txt | w /dev/null # ?

> time read foo.txt ==> /dev/null
> time read foo.txt => /dev/null
> t r foo.txt > /dev/null

> time read foo.txt [1]=> /dev/null
> t r foo.txt 1> /dev/null

> time read foo.txt [1]=>[3]
> t r foo.txt 1>3

@vinc vinc changed the title Update redirections Update shell redirections Aug 27, 2022
@vinc vinc marked this pull request as ready for review August 28, 2022 15:25
@vinc vinc merged commit d5c0002 into trunk Aug 28, 2022
@vinc vinc deleted the feature/update-redirections branch August 28, 2022 15:26
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.

1 participant