Skip to content

Instantly share code, notes, and snippets.

@gentam
Last active June 18, 2018 05:29
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 gentam/5f47198f64f59d5193cd138b13e7b165 to your computer and use it in GitHub Desktop.
Save gentam/5f47198f64f59d5193cd138b13e7b165 to your computer and use it in GitHub Desktop.
format codes to be included in reStructuredText
#!/usr/bin/env bash
[ $# -eq 0 ] && echo "Usage: `basename $0` [filename | *].extention [...]" \
&& exit 1
for f in $@; do
ext=${f##*.}
echo -e "$f\n\n.. code:: $ext"
echo
cat $f \
| sed -e '/^\/\//d' \
| awk '{print " " $0}' \
| sed -e '1d' -e '$a\\n' \
| tr -d '
'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment