scripts

My personal collection of scripts
git clone git://src.gearsix.net/scripts
Log | Files | Refs | Atom | README | LICENSE

commit b472a13ce66eea4c9559ab5ff3484069f8dffb1b
parent eb309814cb1c537e031b29817265b1f6498460c2
Author: gearsix <gearsix@tuta.io>
Date:   Mon, 23 Jan 2023 18:16:27 +0000

fixed preview-md for sh

Diffstat:
Msrc/posix/preview-md.sh | 18++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/posix/preview-md.sh b/src/posix/preview-md.sh @@ -10,21 +10,15 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "convert a Markdown file to HTML using cmark" echo "the generated file will have the same filename as FILE, where the extension is replaced with .html" echo "" - echo "OPTIONS" - echo " -o, --open open the output file (using xdg-open) when finished" exit fi mdconv="cmark" -out=$(echo "$1" | sed "s/\.\?\(md\|txt\|$\)/\.html/") +if [ "$(command -v cmark)" = "" ]; then mdconv="markdown"; + if [ "$(command -v markdown)" = "" ]; then echo "'cmark' or 'markdown' required"; exit; fi; +fi + +out=$(echo "$1" | sed -E "s/\.(md|txt)/\.html/") +if [ -e "$out" ]; then rm -i "$out"; fi -if [ -e "$out" ]; then rm -i $out; fi $mdconv "$1" > "$out" -if [ $? -eq 0 ]; then - echo "succesfully converted to $out" - if [ ! -z $2 ] && [ "$2" = "--open" ] || [ "$2" = "-o" ]; then - xdg-open "$out" &>/dev/null - fi -else - echo "$mdconv returned $?" -fi