I note twothree potential problems with your approach, both dealing with special characters in filenames, as well as one unrelated suggestion one comment on the example usage.
PipingMarkdown
BothMarkdown cares about special names, too. What if I had a file named wca** b **c? Your script would give me a header:
**a** b **c**
a b c
But that's probably not what you intended. You probably want to enclose it in backticks:
**`a** b **c`**
a** b **c
But even that's not enough. What if my file names have backticks, like, say, a` b `c?
**`a` b `c`**
a b c
That's no good! You have to then double-backtick it:
**``a` b `c``**
a` b `c
Essentially, you have to count the maximum number of consecutive backticks and enclose it in that-number-plus-one of backticks.
Example usage
You suggest
mdproj.sh -name *.h -or -name *.cpp > whatever.md
but that will only work when there are exactly zero or one files whose name end with sed.h can openand exactly zero or one files whose name end with .cpp. Consider how it expands when there are no files:
mdproj.sh -name *.h -or -name *.cpp > whatever.md
That's right; Bash leaves them in place, passing them on their ownto find, where it looks for files not of the patterns, but of the exact names (special characters and all) *.h and *.cpp. You can removeSince there are no such files (otherwise, Bash would have substituted them in) find will not find the redirections:files, and so nothing will happen. What if there is example.h and example.cpp?
bytes="$(wcmdproj.sh -cname "$path")example.h bytes"-or -name example.cpp > whatever.md
lines="$(wc
That works fine. What if there are multiple?
mdproj.sh -lname "$path")foo.h lines"bar.h -or -name foo.cpp bar.cpp > whatever.md
sed
Uh oh. -name takes only one value, but you're passing it two. My find dies with this error:
find: "s/^/bar.h: unknown option
I always use -regex for that sort of thing:
mdproj.sh -regex /"'.*\.h' "$path"-or -regex '.*\.cpp' > whatever.md
(If I was being cleverer, I might use -E and merge them into one regular expression.)