Skip to content

Instantly share code, notes, and snippets.

@secretGeek
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secretGeek/b6d28bfa1b825c37b170 to your computer and use it in GitHub Desktop.
Save secretGeek/b6d28bfa1b825c37b170 to your computer and use it in GitHub Desktop.
chapters.ps1 -- gives me a basic table of contents for the book I'm working on, include count of words and remaining todo's in each chapter.
$totalWords = 0
$totalTodo = 0;
dir *.md | % {
$name = $_.Name;
$len = $_.length;
$todos = (get-content $_ | select-string -pattern "//TODO:").length
$subChapters = (get-content $_ | select-string -pattern "^### ").length
$words = (get-content $_ | measure-object -word).Words;
$totalWords = $totalWords + $words;
$totalTodo = $totalTodo + $todos;
New-Object PSCustomObject -Property @{
"Name"=$_.Name;
"Length"=$_.Length;
"Words"=$words
"Todos"=$todos
"SubChapters"=$subChapters
}
} | format-table -property Length, Words, Todos, SubChapters, Name
write-host "Words: $totalWords, TODO: $totalTodo" -foregroundcolor "white"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment