From 72b20935866c22daa4fd75bd35229aa36e96f5d5 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 4 Sep 2022 14:47:09 -0300 Subject: git mv bin/html bin/htmlesc --- bin/html | 96 ------------------------------------------------------------- bin/htmlesc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 96 deletions(-) delete mode 100755 bin/html create mode 100755 bin/htmlesc diff --git a/bin/html b/bin/html deleted file mode 100755 index f3f23de..0000000 --- a/bin/html +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/sh -set -eu - - -usage() { - cat <<-'EOF' - Usage: - html [-e|d] - html -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -e escape the string (the default action) - -d unescape (de-escape?) the string - -h, --help show this message - - - Get a string from STDIN and convert it to/from HTML escaping. - - - Examples: - - oij - - $ printf 'a > 5 && !b' | html - a > 5 && !b - - - Unescape the content from a file: - - $ html -d < file.html - EOF -} - - -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - *) - ;; - esac -done - -ENCODE=false -DECODE=false -while getopts 'edh' flag; do - case "$flag" in - e) - ENCODE=true - ;; - d) - DECODE=true - ;; - h) - usage - help - exit - ;; - *) - usage >&2 - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -if [ "$ENCODE" = true ] && [ "$DECODE" = true ]; then - printf 'Both -e and -d given. Pick one.\n' >&2 - usage >&2 - exit 2 -elif [ "$DECODE" = true ]; then - sed \ - -e 's|&|\&|g' \ - -e 's|<|<|g' \ - -e 's|>|>|g' \ - -e 's|"|"|g' \ - -e "s|'|'|g" -else - sed \ - -e 's|&|\&|g' \ - -e 's|<|\<|g' \ - -e 's|>|\>|g' \ - -e 's|"|\"|g' \ - -e "s|'|\'|g" -fi diff --git a/bin/htmlesc b/bin/htmlesc new file mode 100755 index 0000000..d9c59bd --- /dev/null +++ b/bin/htmlesc @@ -0,0 +1,96 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + htmlesc [-e|d] + htmlesc -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -e escape the string (the default action) + -d unescape (de-escape?) the string + -h, --help show this message + + + Get a string from STDIN and convert it to/from HTML escaping. + + + Examples: + + oij + + $ printf 'a > 5 && !b' | htmlesc + a > 5 && !b + + + Unescape the content from a file: + + $ htmlesc -d < file.html + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +ENCODE=false +DECODE=false +while getopts 'edh' flag; do + case "$flag" in + e) + ENCODE=true + ;; + d) + DECODE=true + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ "$ENCODE" = true ] && [ "$DECODE" = true ]; then + printf 'Both -e and -d given. Pick one.\n' >&2 + usage >&2 + exit 2 +elif [ "$DECODE" = true ]; then + sed \ + -e 's|&|\&|g' \ + -e 's|<|<|g' \ + -e 's|>|>|g' \ + -e 's|"|"|g' \ + -e "s|'|'|g" +else + sed \ + -e 's|&|\&|g' \ + -e 's|<|\<|g' \ + -e 's|>|\>|g' \ + -e 's|"|\"|g' \ + -e "s|'|\'|g" +fi -- cgit v1.2.3