1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-16 13:38:02 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nick-w-nick
c0f4e2191f Merge 295fe153ad into 409201611f 2025-02-10 11:43:37 -05:00
jbranchaud
409201611f Add Get Word Count For All Files In Git Repo as a Unix TIL 2025-02-08 18:07:54 -06:00
nick-w-nick
295fe153ad added mention of ES6 compatibility
Hello, I've added a small blockquote below the description to indicate that this method of accessing an indefinite number of function arguments has been superseded by the use of the spread operator via rest parameters for ES6+ compatibility.
2022-01-06 11:39:04 -05:00
3 changed files with 36 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1586 TILs and counting..._
_1587 TILs and counting..._
See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -1536,6 +1536,7 @@ See some of the other learning resources I work on:
- [Get Matching Filenames As Output From Grep](unix/get-matching-filenames-as-output-from-grep.md)
- [Get The SHA256 Hash For A File](unix/get-the-sha256-hash-for-a-file.md)
- [Get The Unix Timestamp](unix/get-the-unix-timestamp.md)
- [Get Word Count For All Files In Git Repo](unix/get-word-count-for-all-files-in-git-repo.md)
- [Global Substitution On The Previous Command](unix/global-substitution-on-the-previous-command.md)
- [Globbing For All Directories In Zsh](unix/globbing-for-all-directories-in-zsh.md)
- [Globbing For Filenames In Zsh](unix/globbing-for-filenames-in-zsh.md)

View File

@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
all of the arguments are referenced in the function signature, they can
still be accessed via the `arguments` object.
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
```javascript
function argTest(one) {
console.log(one);

View File

@@ -0,0 +1,32 @@
# Get Word Count For All Files In Git Repo
As part of gathering numbers for [A Decade of TILs](), I wanted to get an word
count of all the TIL markdown files I've committed to this project over its 10
year history. By using `git ls-files` with a pattern, I can get a list of all
file names. Then with `xargs` I can pass that entire list to `wc -w` which
gives a word count of each. The final line that `wc -w` outputs is a sum total
of all the file word counts. Lastly, piping that through `tail -n1` gives me
just that last total count line.
```bash
$ git ls-files "*/**.md" | xargs wc -w | tail -n1
206816 total
```
Since the `tail -n1` obfuscates what the `wc -w` is doing, here is what that
looks like before that final pipe.
```bash
$ git ls-files "*/**.md" | tail -n3 | xargs wc -w
115 zsh/add-to-the-path-via-path-array.md
190 zsh/link-a-scalar-to-an-array.md
214 zsh/use-a-space-to-exclude-command-from-history.md
519 total
```
I can even clean up the final output a bit more with `awk`:
```bash
$ git ls-files "*/**.md" | xargs wc -w | tail -n1 | awk '{print $1}'
206816
```