Skip to content

Commit

Permalink
Merge pull request ekalinin#44 from chrisob/linux_fix
Browse files Browse the repository at this point in the history
Fix sed syntax for Linux
  • Loading branch information
ekalinin authored Feb 28, 2018
2 parents 590e641 + 41236dc commit 1590bc1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ gh_toc(){
local toc=`gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"`
echo "$toc"
if [ "$need_replace" = "yes" ]; then
local ts="\<\!--ts--\>"
local te="\<\!--te--\>"
local ts="<\!--ts-->"
local te="<\!--te-->"
local dt=`date +'%F_%H%M%S'`
local ext=".orig.${dt}"
local toc_path="${gh_src}.toc.${dt}"
local toc_footer="<!-- Added by: `whoami`, at: `date --iso-8601='minutes'` -->"
# http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
# clear old TOC
sed -i "${ext}" -e "/${ts}/,/${te}/ {//!d;}" "$gh_src"
sed -i${ext} "/${ts}/,/${te}/{//!d}" "$gh_src"
# create toc file
echo "${toc}" > "${toc_path}"
echo -e "\n${toc_footer}\n" >> "$toc_path"
# insert toc file
sed -i "" -e "/${ts}/r ${toc_path}" "$gh_src"
sed -i "/${ts}/r ${toc_path}" "$gh_src"
echo
echo "!! TOC was added into: '$gh_src'"
echo "!! Origin version of the file: '${gh_src}${ext}'"
Expand Down

0 comments on commit 1590bc1

Please sign in to comment.