diff options
author | EuAndreh <eu@euandre.org> | 2024-11-17 19:50:40 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-17 19:50:40 -0300 |
commit | 252710a61d328e0840da54fe21b55e74ab53c03a (patch) | |
tree | b3b5503ccb2ded4a4e15be71f0cb04fcc9e00440 | |
parent | rm- rf src/development/ (diff) | |
download | euandre.org-252710a61d328e0840da54fe21b55e74ab53c03a.tar.gz euandre.org-252710a61d328e0840da54fe21b55e74ab53c03a.tar.xz |
rm src/bin/pb
-rwxr-xr-x | src/bin/pb | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/src/bin/pb b/src/bin/pb deleted file mode 100755 index 48979e2..0000000 --- a/src/bin/pb +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/sh -set -eu - -cd -- "$(dirname -- "$(readlink -f -- "$0")")"/../../ - - -usage() { - cat <<-'EOF' - Usage: - pb -t TITLE [-l LANGUAGE] [-s SLUG] - pb -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 -} - - -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")" - -trap 'rm -f "$OUT-tmp"' EXIT -# shellcheck disable=2016 -cat <<-EOF | e > "$OUT-tmp" - --- - - title: $TITLE - - date: $DATE - - layout: post - - lang: en - - ref: $SLUG - - --- - - \`\`\`$LANGUAGE - $(cat | sed 's|^```$|\\`\\`\\`|') - \`\`\` -EOF - -exec 0</dev/tty -if ! prompt 'Proceed with publishing the snippet?'; then - printf 'Aborted.\n' >&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 |