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

Count from stdin #5744

Merged
merged 3 commits into from Mar 15, 2019
Merged

Count from stdin #5744

merged 3 commits into from Mar 15, 2019

Conversation

faho
Copy link
Member

@faho faho commented Mar 14, 2019

Description

This allows our count builtin to also count lines fed from stdin.

  • Like string, it will only do so when it's directly redirected.

  • It will still count the arguments and add them together.

  • It will count newlines, so echo -n results in 0. This is also what wc -l does.

This removes uses of wc -l, which in some versions indents its output, which makes it annoying to work with.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md

As a simple replacement for `wc -l`.

This counts both lines on stdin _and_ arguments.

So if "file" has three lines, then `count a b c < file` will print 6.

And since it counts newlines, like wc, `echo -n foo | count` prints 0.
Removes any uses of `wc` in our codebase.
@faho faho added this to the fish 3.1.0 milestone Mar 14, 2019
@faho faho merged commit b3f3909 into fish-shell:master Mar 15, 2019
@floam
Copy link
Member

floam commented Mar 16, 2019

I think we can diverge from wc -l on printf foo | count.

@faho faho deleted the count-stdin branch April 1, 2019 14:07
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants