scripts

Scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | LICENSE

htmlconv (919B)


      1 #!/bin/bash
      2 
      3 filearg="$1"
      4 
      5 test -z "${filearg}" && echo "Please give file as program argument." >&2 && exit 1
      6 
      7 filename="${filearg%.*}"
      8 extension="${filearg##*.}"
      9 
     10 readonly BROWSER=$(xdg-settings get default-web-browser | xargs echo `sed 's/.desktop//'`)
     11 readonly MARKUP_FILE="$filename.$extension"
     12 
     13 readonly OUTPUT_FILE="$filename.html"
     14 
     15 test ! -f "$MARKUP_FILE" && echo "\"$MARKUP_FILE\" not found." >&2 && exit 1
     16 
     17 case "$extension" in 
     18 	"adoc"|"asciidoc")
     19 		asciidoctor -o "$OUTPUT_FILE" "$MARKUP_FILE";;
     20 	"md")
     21 		md2html -f -o "$OUTPUT_FILE" "$MARKUP_FILE";;
     22 	*) 
     23 		echo "$extension is not supported" >&2 && exit 1;;
     24 esac
     25 
     26 window_id=$(xdotool search --onlyvisible --class "$BROWSER")
     27 
     28 if [ -n "$window_id" ]; then
     29 	xdotool key --window $window_id ctrl+l ctrl+c Escape
     30 	name=$(xclip -o -selection clipboard)
     31 	[[ $name == *"$OUTPUT_FILE" ]] && xdotool key --window $window_id F5 && exit 0
     32 fi
     33 
     34 $BROWSER $OUTPUT_FILE &