#!/bin/bash # NAME # reformat-html - reformat HTML files from emailselfdefense.fsf.org # SYNOPSIS # reformat-html /PATH/TO/NAME.html # GRAPHIC INTERFACE HOWTO # * Launch the script by double-clicking on it; a terminal will open. # * At the prompt, drag and drop the input file into the terminal. # # Alternatively (in Gnome, KDE, XFCE, etc.) # * create a launcher for the application menu; # * launch the script from the contextual menu of the HTML file. # # The reformatted file is created in the directory where the input file # resides, and its name is NAME-r.html. #============================================================================== set -e # Test whether the script is called from color-wdiff p=$(pidof -x color-wdiff) || true test "$p" == "$PPID" && called_from_color_wdiff=1 function sleep_or_exit () { # turns off interactivity and lets the terminal close normally if the script # is called from color-wdiff. if test "$called_from_color_wdiff" == "1"; then exit $1 else if test "$1" == "1"; then echo -e 1>&2 "\n!!! $input doesn't exist or is not HTML." sleep 3 fi exit $1 fi } # Get a valid HTML as input. input=$1 if test ! -f "$input" -o ! -s "$input"; then echo -e "\n*** reformat-html - Please enter the HTML file." read input input=${input%\'}; input=${input#\'} fi test -f "$input" -a "${input%.html}" != "$input" || sleep_or_exit 1 # Define the output file. if test "$called_from_color_wdiff" == "1"; then output=$2 else output=${input%.html}-r.html fi tmp=$(mktemp -t ref.XXXXXX) || exit 1 tmp1=$(mktemp -t ref.XXXXXX) || exit 1 tmp2=$(mktemp -t ref.XXXXXX) || exit 1 trap 'rm -f "$tmp" "$tmp1" "$tmp2"' EXIT # Don't touch the scripts. sed -n '/