Skip to content

Instantly share code, notes, and snippets.

@secretGeek secretGeek/chapters.ps1
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.