commit 16c462398afee4caebd8bd665fe6131a3ea81d0e parent 85fbf3534c4e3356c800c823ce06300144f25a25 Author: Wim Dupont <wim@wimdupont.com> Date: Mon, 10 Jun 2024 07:31:03 +0200 added adoc Diffstat:
M | README.adoc | | | 10 | ++++++++++ |
A | bin/adoc | | | 26 | ++++++++++++++++++++++++++ |
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/README.adoc b/README.adoc @@ -2,6 +2,16 @@ For certain scripts I've added a "requires" section to specify software which is less likely to be installed by default that the script uses. Most of these can be changed with alternatives by choice if willing to edit the script. :toc: +== link:bin/adoc[adoc] + +Generates html for asciidoc file and opens in browser or refreshes if current tab has +the html filename in URL. + +.Requires: + +* https://github.com/astrand/xclip[xclip] +* https://github.com/jordansissel/xdotool[xdotool] + == link:bin/askpass[askpass] Prompts for sudo password - using Zenity GUI only when using display server. Meant to be used with addition to the sudo.conf: diff --git a/bin/adoc b/bin/adoc @@ -0,0 +1,26 @@ +#!/bin/bash + +filename="$1" + +test -z "${filename}" && echo "Please give file as program argument." >&2 && exit 1 + +filename="${filename%.*}" + +readonly BROWSER=$(xdg-settings get default-web-browser | xargs echo `sed 's/.desktop//'`) +readonly ADOC_FILE="$filename.adoc" +readonly OUTPUT_FILE="$filename.html" + +asciidoctor -o "$OUTPUT_FILE" "$ADOC_FILE" + +window_id=$(xdotool search --onlyvisible --class "$BROWSER") + +if [ -n "$window_id" ]; then + xdotool key --window $window_id ctrl+l ctrl+c Escape + clipboard=$(xclip -o -selection clipboard) + name=$(echo "$clipboard") + if [[ $name == *"$filename"* ]]; then + xdotool key --window $window_id F5 && exit 0 + fi +fi + +$BROWSER $OUTPUT_FILE &