aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/htmlesc118
-rwxr-xr-xbin/shesc85
-rwxr-xr-xbin/uri81
3 files changed, 0 insertions, 284 deletions
diff --git a/bin/htmlesc b/bin/htmlesc
deleted file mode 100755
index 5f3694f..0000000
--- a/bin/htmlesc
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/sh
-set -eu
-
-
-usage() {
- cat <<-'EOF'
- Usage:
- htmlesc [-e|d] [CONTENT...]
- 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
-
- CONTENT a literal string to be escaped
-
-
- Convert data to/from HTML escaping. If CONTENT is not given,
- get data from STDIN.
-
-
- Examples:
-
- Escape HTML control characters in a string:
-
- $ htmlesc 'a > 5 && !b'
- a &gt; 5 &amp;&amp; !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
-fi
-
-decode() {
- sed \
- -e 's|&amp;|\&|g' \
- -e 's|&lt;|<|g' \
- -e 's|&gt;|>|g' \
- -e 's|&quot;|"|g' \
- -e "s|&apos;|'|g"
-}
-
-encode() {
- sed \
- -e 's|&|\&amp;|g' \
- -e 's|<|\&lt;|g' \
- -e 's|>|\&gt;|g' \
- -e 's|"|\&quot;|g' \
- -e "s|'|\&apos;|g"
-}
-
-if [ "$DECODE" = true ]; then
- FN=decode
-else
- FN=encode
-fi
-
-if [ $# = 0 ]; then
- "$FN"
-else
- for s in "$@"; do
- printf '%s\n' "$s" | "$FN"
- done
-fi
diff --git a/bin/shesc b/bin/shesc
deleted file mode 100755
index b7a4a1b..0000000
--- a/bin/shesc
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/sh
-set -eu
-
-
-usage() {
- cat <<-'EOF'
- Usage:
- shesc [CONTENT...]
- shesc -h
- EOF
-}
-
-help() {
- cat <<-'EOF'
-
-
- Options:
- -h, --help show this message
-
- CONTENT a literal string to be escaped
-
-
- Convert data to/from POSIX sh double quote string escaping. If
- CONTENT is not given, get data from STDIN.
-
-
- Examples:
-
- Escape sh control characters in a string:
-
- $ printf 'content="%s"\n' "$(shesc '"string" $(dollar "`cmd`") \ ')"
- content="\"string\" \$(dollar \"\`cmd\`\") \\ "
-
-
- Escape the content from a file:
-
- $ shesc < file.conf
- EOF
-}
-
-
-for flag in "$@"; do
- case "$flag" in
- (--)
- break
- ;;
- (--help)
- usage
- help
- exit
- ;;
- (*)
- ;;
- esac
-done
-
-while getopts 'h' flag; do
- case "$flag" in
- (h)
- usage
- help
- exit
- ;;
- (*)
- usage >&2
- exit 2
- ;;
- esac
-done
-shift $((OPTIND - 1))
-
-
-
-esc() {
- sed 's|\([\\`"$]\)|\\\1|g'
-}
-
-
-if [ $# = 0 ]; then
- esc
-else
- for s in "$@"; do
- printf '%s\n' "$s" | esc
- done
-fi
diff --git a/bin/uri b/bin/uri
deleted file mode 100755
index bbe67ef..0000000
--- a/bin/uri
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env perl
-
-use v5.34;
-use warnings;
-use feature 'signatures';
-no warnings ('experimental::signatures');
-use Getopt::Std ();
-use URI::Escape ();
-
-sub usage($fh) {
- print $fh <<~'EOF';
- Usage:
- uri [-e|-d] [CONTENT...]
- uri -h
- EOF
-}
-
-sub help($fh) {
- print $fh <<~'EOF';
-
-
- Options:
- -e encode the string (the default action)
- -d decode the string
- -h, --help show this message
-
- CONTENT a literal string to be escaped
-
-
- Convert data to/from URL encoding. If CONTENT is not given, get
- data from STDIN.
-
-
- Examples:
-
- Encode the URL:
-
- $ echo "https://euandre.org/?q=$(uri 'a param')"
- https://euandre.org/?q=a%20param
-
-
- Decode the content from the file:
-
- $ uri -d < file
- EOF
-}
-
-for (@ARGV) {
- last if $_ eq '--';
- if ($_ eq '--help') {
- usage *STDOUT;
- help *STDOUT;
- exit;
- }
-}
-
-my %opts;
-if (!Getopt::Std::getopts('edh', \%opts)) {
- usage *STDERR;
- exit 2;
-}
-
-if ($opts{h}) {
- usage *STDOUT;
- help *STDOUT;
- exit;
-} elsif ($opts{e} and $opts{d}) {
- say STDERR 'Both -e and -d given. Pick one.';
- say STDERR '';
- usage *STDERR;
- exit 2;
-}
-
-
-my $fn = $opts{d} ? \&URI::Escape::uri_unescape : \&URI::Escape::uri_escape;
-
-$|++;
-
-while ($_ = (@ARGV ? @ARGV : <STDIN>)) {
- print &$fn($_);
-}