Skip to content

Instantly share code, notes, and snippets.

@gdvalle
Created February 18, 2017 21:33
Show Gist options
  • Save gdvalle/c98dce649818c775a5be3db2488360bc to your computer and use it in GitHub Desktop.
Save gdvalle/c98dce649818c775a5be3db2488360bc to your computer and use it in GitHub Desktop.
Replace text between invisible markdown comments.
#!/usr/bin/env bash
# This just replaces the text between a couple of hopefully invisible
# markdown comments, like so: `[//]: #` (text within backticks)
set -euo pipefail
main_output="$(cargo run -- --help)"
output="$(printf "### main\n\`\`\`\n%s\n\`\`\`" "$main_output")\n"
output+="### subcommands\n"
for subcmd in subcmd1 subcmd2; do
subcmd_output="$(cargo run -- "$subcmd" --help)"
output+="$(printf "#### %s\n\`\`\`\n%s\n\`\`\`" "$subcmd" "$subcmd_output")\n"
done
perl -i -pe "BEGIN{undef $/;} s@\[//\]: #\n.*\[//\]: #\$@[//]: #\n${output}[//]: #@smg" README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment