From 732ca475f62a3336ff38f2f35fc826c21a82eb19 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 1 Jun 2022 17:53:36 -0300 Subject: git mv bin/ src/ --- bin/article | 143 --------------------------------------------- bin/pb | 175 -------------------------------------------------------- bin/tmp | 74 ------------------------ src/bin/article | 143 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/pb | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/bin/tmp | 74 ++++++++++++++++++++++++ 6 files changed, 392 insertions(+), 392 deletions(-) delete mode 100755 bin/article delete mode 100755 bin/pb delete mode 100755 bin/tmp create mode 100755 src/bin/article create mode 100755 src/bin/pb create mode 100755 src/bin/tmp diff --git a/bin/article b/bin/article deleted file mode 100755 index a6ce748..0000000 --- a/bin/article +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/sh -set -eu - -usage() { - cat <<-'EOF' - Usage: - article - article -h - EOF -} - -help() { - cat <<-'EOF' - - - Options: - -h, --help show this message - - - Examples: - - FIXME: - - $ FIXME - $0 til 'I just learned this' - $0 article 'My example article title' - EOF -} - - - - -TYPE="${1:-}" -[ -z "$TYPE" ] && { - missing 'TYPE' - usage - exit 2 -} - -EXTRA='' -case "$TYPE" in - article|til) - LAYOUT=post - DIR="_${TYPE}s" - EXT=md - ;; - podcast|screencast) - LAYOUT=post - DIR="_${TYPE}s" - EXT=md - EXTRA=" -$TYPE: true -" - ;; - slides) - LAYOUT=slides - DIR=_slides - EXT=slides - ;; - *) - red "Invalid type '$TYPE'\n" >&2 - usage - exit 2 - ;; -esac - -FULL_TITLE="${2:-}" -[ -z "$FULL_TITLE" ] && { - missing 'FULL_TITLE' - usage - exit 2 -} - -# Derived from: -# https://stackoverflow.com/questions/4009281/how-can-i-generate-url-slugs-in-perl/4009519#4009519 -slugify() { - echo "$1" | \ - tr '[:upper:]' '[:lower:]' | \ - perl -ne 'tr/\000-\177//cd; - s/[^\w\s-]//g; - s/^\s+|\s+$//g; - s/[-\s]+/-/g; - print;' -} - -WEBSITE_REPO="$HOME/dev/libre/website" -SLUG_TITLE="$(slugify "$FULL_TITLE")" -PASTE_DATE="$(date -I)" -OUT="$WEBSITE_REPO/$DIR/$PASTE_DATE-$SLUG_TITLE.$EXT" - -cd "$WEBSITE_REPO" - -if [ -f "$OUT" ]; then - exec vi "$OUT" -fi - -if [ "$LAYOUT" = 'slides' ]; then - ARTICLE="$($0 article "$FULL_TITLE")" - cat< "$OUT" ---- - -title: $FULL_TITLE - -date: $PASTE_DATE - -layout: $LAYOUT - -lang: en - -ref: $SLUG_TITLE - -article: $ARTICLE -$EXTRA ---- - ---- - -## Thank you! - -References: - -1. FIXME -2. FIXME -EOF -else - cat < "$OUT" ---- - -title: $FULL_TITLE - -date: $PASTE_DATE - -layout: $LAYOUT - -lang: en - -ref: $SLUG_TITLE - ---- -EOF -fi - -vi "$OUT" diff --git a/bin/pb b/bin/pb deleted file mode 100755 index 0e71da5..0000000 --- a/bin/pb +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/sh -set -eu - - -WEBSITE_DIR=~/dev/libre/website - - -usage() { - cat <<-'EOF' - Usage: - pb -t TITLE [-l LANGUAGE] [-s SLUG] - pg -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -t TITLE the title of the snippet - -l LANGUAGE the programming language of the snippet - -s SLUG the URL slug of the snippet - - Examples: - - FIXME: - - $ FIXME - EOF -} - - -slugify() { - iconv -ct ASCII//TRANSLIT | - tr '[:upper:]' '[:lower:]' | - sed -e 's/[^a-z0-9]/-/g' \ - -e 's/--*/-/g' \ - -e 's/^-//' \ - -e 's/-$//' -} - -prompt() { - printf '%s [Y/n]: ' "$1" - read -r yesno - if [ "$yesno" = 'n' ] || [ "$yesno" = 'N' ]; then - return 1 - else - return 0 - fi -} - -outname() { - DATE=$1 - SLUG=$2 - N="${3:-0}" - if [ "$N" = 0 ]; then - SUFFIX='' - else - SUFFIX="-$N" - fi - F="_pastebins/$DATE-$SLUG$SUFFIX.md" - if [ -e "$F" ]; then - outname "$DATE" "$SLUG" $((N + 1)) - else - # FIXME - eval "SLUG=$SLUG$SUFFIX" - printf '%s' "$F" - fi -} - -url() { - DATE="$1" - SLUG="$2" - printf 'https://%s/pastebin/%s/%s.html' \ - "$(make -s fqdn)" \ - "$(echo "$DATE" | tr '-' '/')" \ - "$SLUG" -} - - -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - *) - ;; - esac -done - -while getopts 't:l:s:h' flag; do - case "$flag" in - t) - TITLE="$OPTARG" - ;; - l) - LANGUAGE="$OPTARG" - ;; - s) - SLUG="$OPTARG" - ;; - h) - usage - help - exit - ;; - *) - usage >&2 - exit 2 - ;; - esac -done - -assert_arg() { - if [ -z "$1" ]; then - { - printf 'Missing %s.\n' "$2" - printf '\n' - usage - } >&2 - exit 2 - fi -} - -cd "$WEBSITE_DIR" - -assert_arg "${TITLE:-}" '-t TITLE' -LANGUAGE="${LANGUAGE:-}" -DATE="$(date '+%Y-%m-%d')" -SLUG="${SLUG:-$(echo "$TITLE" | slugify)}" -OUT="$(outname "$DATE" "$SLUG")" -URL="$(url "$DATE" "$SLUG")" - -# shellcheck disable=2064 -trap "rm -f '$OUT-tmp'" EXIT -cat <<-EOF | vipe > "$OUT-tmp" - --- - - title: $TITLE - - date: $DATE - - layout: post - - lang: en - - ref: $SLUG - - --- - - \`\`\`$LANGUAGE - $(cat | sed "s|^```\$|\\\\\`\\\\\`\\\\\`|') - \`\`\` -EOF - -exec 0&2 - exit -fi - -mv "$OUT-tmp" "$OUT" -git reset . -git add "$OUT" -git commit -m "pastebin: Auto-add $OUT" -make deploy - -open "$URL" -printf '%s' "$URL" | copy -printf 'Opened on the browser and copied URL to clipboard.\n' >&2 diff --git a/bin/tmp b/bin/tmp deleted file mode 100755 index 80cadd9..0000000 --- a/bin/tmp +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -set -eu - -usage() { - cat <<-'EOF' - Usage: - tmp FILE... - tmp -d - tmp -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -d delete the remote "tmp/" folder - -h, --help show this message - EOF -} - -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - *) - ;; - esac -done - -TLD='euandre.org' -REMOTE_TMP='/home/user-data/www/default/tmp' -while getopts 'dh' flag; do - case "$flag" in - d) - printf 'Deleting %s:%s...\n' "$TLD" "$REMOTE_TMP/" >&2 - ssh "$TLD" rm -rf "$REMOTE_TMP" - exit - ;; - h) - usage - help - exit - ;; - *) - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -if [ -z "${1:-}" ]; then - usage >&2 - exit 2 -fi - -for f in "$@"; do - FILENAME="$(basename "$f")" - # shellcheck disable=2029 - ssh "$TLD" "mkdir -p '$REMOTE_TMP' && cat > '$REMOTE_TMP/$FILENAME'" < "$f" - - LINK="$(printf 'https://%s/tmp/%s' "$TLD" "$FILENAME")" - open "$LINK" - if [ $# = 1 ]; then - printf '%s' "$LINK" | copy - printf 'Copied %s to the clipboard!\n' "$LINK" >&2 - fi -done diff --git a/src/bin/article b/src/bin/article new file mode 100755 index 0000000..a6ce748 --- /dev/null +++ b/src/bin/article @@ -0,0 +1,143 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + article + article -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Examples: + + FIXME: + + $ FIXME + $0 til 'I just learned this' + $0 article 'My example article title' + EOF +} + + + + +TYPE="${1:-}" +[ -z "$TYPE" ] && { + missing 'TYPE' + usage + exit 2 +} + +EXTRA='' +case "$TYPE" in + article|til) + LAYOUT=post + DIR="_${TYPE}s" + EXT=md + ;; + podcast|screencast) + LAYOUT=post + DIR="_${TYPE}s" + EXT=md + EXTRA=" +$TYPE: true +" + ;; + slides) + LAYOUT=slides + DIR=_slides + EXT=slides + ;; + *) + red "Invalid type '$TYPE'\n" >&2 + usage + exit 2 + ;; +esac + +FULL_TITLE="${2:-}" +[ -z "$FULL_TITLE" ] && { + missing 'FULL_TITLE' + usage + exit 2 +} + +# Derived from: +# https://stackoverflow.com/questions/4009281/how-can-i-generate-url-slugs-in-perl/4009519#4009519 +slugify() { + echo "$1" | \ + tr '[:upper:]' '[:lower:]' | \ + perl -ne 'tr/\000-\177//cd; + s/[^\w\s-]//g; + s/^\s+|\s+$//g; + s/[-\s]+/-/g; + print;' +} + +WEBSITE_REPO="$HOME/dev/libre/website" +SLUG_TITLE="$(slugify "$FULL_TITLE")" +PASTE_DATE="$(date -I)" +OUT="$WEBSITE_REPO/$DIR/$PASTE_DATE-$SLUG_TITLE.$EXT" + +cd "$WEBSITE_REPO" + +if [ -f "$OUT" ]; then + exec vi "$OUT" +fi + +if [ "$LAYOUT" = 'slides' ]; then + ARTICLE="$($0 article "$FULL_TITLE")" + cat< "$OUT" +--- + +title: $FULL_TITLE + +date: $PASTE_DATE + +layout: $LAYOUT + +lang: en + +ref: $SLUG_TITLE + +article: $ARTICLE +$EXTRA +--- + +--- + +## Thank you! + +References: + +1. FIXME +2. FIXME +EOF +else + cat < "$OUT" +--- + +title: $FULL_TITLE + +date: $PASTE_DATE + +layout: $LAYOUT + +lang: en + +ref: $SLUG_TITLE + +--- +EOF +fi + +vi "$OUT" diff --git a/src/bin/pb b/src/bin/pb new file mode 100755 index 0000000..0e71da5 --- /dev/null +++ b/src/bin/pb @@ -0,0 +1,175 @@ +#!/bin/sh +set -eu + + +WEBSITE_DIR=~/dev/libre/website + + +usage() { + cat <<-'EOF' + Usage: + pb -t TITLE [-l LANGUAGE] [-s SLUG] + pg -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -t TITLE the title of the snippet + -l LANGUAGE the programming language of the snippet + -s SLUG the URL slug of the snippet + + Examples: + + FIXME: + + $ FIXME + EOF +} + + +slugify() { + iconv -ct ASCII//TRANSLIT | + tr '[:upper:]' '[:lower:]' | + sed -e 's/[^a-z0-9]/-/g' \ + -e 's/--*/-/g' \ + -e 's/^-//' \ + -e 's/-$//' +} + +prompt() { + printf '%s [Y/n]: ' "$1" + read -r yesno + if [ "$yesno" = 'n' ] || [ "$yesno" = 'N' ]; then + return 1 + else + return 0 + fi +} + +outname() { + DATE=$1 + SLUG=$2 + N="${3:-0}" + if [ "$N" = 0 ]; then + SUFFIX='' + else + SUFFIX="-$N" + fi + F="_pastebins/$DATE-$SLUG$SUFFIX.md" + if [ -e "$F" ]; then + outname "$DATE" "$SLUG" $((N + 1)) + else + # FIXME + eval "SLUG=$SLUG$SUFFIX" + printf '%s' "$F" + fi +} + +url() { + DATE="$1" + SLUG="$2" + printf 'https://%s/pastebin/%s/%s.html' \ + "$(make -s fqdn)" \ + "$(echo "$DATE" | tr '-' '/')" \ + "$SLUG" +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 't:l:s:h' flag; do + case "$flag" in + t) + TITLE="$OPTARG" + ;; + l) + LANGUAGE="$OPTARG" + ;; + s) + SLUG="$OPTARG" + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done + +assert_arg() { + if [ -z "$1" ]; then + { + printf 'Missing %s.\n' "$2" + printf '\n' + usage + } >&2 + exit 2 + fi +} + +cd "$WEBSITE_DIR" + +assert_arg "${TITLE:-}" '-t TITLE' +LANGUAGE="${LANGUAGE:-}" +DATE="$(date '+%Y-%m-%d')" +SLUG="${SLUG:-$(echo "$TITLE" | slugify)}" +OUT="$(outname "$DATE" "$SLUG")" +URL="$(url "$DATE" "$SLUG")" + +# shellcheck disable=2064 +trap "rm -f '$OUT-tmp'" EXIT +cat <<-EOF | vipe > "$OUT-tmp" + --- + + title: $TITLE + + date: $DATE + + layout: post + + lang: en + + ref: $SLUG + + --- + + \`\`\`$LANGUAGE + $(cat | sed "s|^```\$|\\\\\`\\\\\`\\\\\`|') + \`\`\` +EOF + +exec 0&2 + exit +fi + +mv "$OUT-tmp" "$OUT" +git reset . +git add "$OUT" +git commit -m "pastebin: Auto-add $OUT" +make deploy + +open "$URL" +printf '%s' "$URL" | copy +printf 'Opened on the browser and copied URL to clipboard.\n' >&2 diff --git a/src/bin/tmp b/src/bin/tmp new file mode 100755 index 0000000..80cadd9 --- /dev/null +++ b/src/bin/tmp @@ -0,0 +1,74 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + tmp FILE... + tmp -d + tmp -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -d delete the remote "tmp/" folder + -h, --help show this message + EOF +} + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +TLD='euandre.org' +REMOTE_TMP='/home/user-data/www/default/tmp' +while getopts 'dh' flag; do + case "$flag" in + d) + printf 'Deleting %s:%s...\n' "$TLD" "$REMOTE_TMP/" >&2 + ssh "$TLD" rm -rf "$REMOTE_TMP" + exit + ;; + h) + usage + help + exit + ;; + *) + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ -z "${1:-}" ]; then + usage >&2 + exit 2 +fi + +for f in "$@"; do + FILENAME="$(basename "$f")" + # shellcheck disable=2029 + ssh "$TLD" "mkdir -p '$REMOTE_TMP' && cat > '$REMOTE_TMP/$FILENAME'" < "$f" + + LINK="$(printf 'https://%s/tmp/%s' "$TLD" "$FILENAME")" + open "$LINK" + if [ $# = 1 ]; then + printf '%s' "$LINK" | copy + printf 'Copied %s to the clipboard!\n' "$LINK" >&2 + fi +done -- cgit v1.2.3