From 3e0715604dc36f30b7464949d77a3ccb0083f440 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 15 Jun 2021 09:36:03 -0300 Subject: sh/fzf.sh: Create separate cn() (commit number) and cm() (commit) functions --- scripts/pastebin | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/pastebin.sh | 84 ----------------------------------------------------- 2 files changed, 84 insertions(+), 84 deletions(-) create mode 100755 scripts/pastebin delete mode 100755 scripts/pastebin.sh (limited to 'scripts') diff --git a/scripts/pastebin b/scripts/pastebin new file mode 100755 index 00000000..319b1266 --- /dev/null +++ b/scripts/pastebin @@ -0,0 +1,84 @@ +#!/bin/sh +set -eu + +usage() { + cat <. + +Usage: + $0 [-|FILE] + + Reads contents from [FILE], from stdin if '-' is given, and opens the + editor on the content. + + Arguments: + FULL_TITLE Full title of the pastebin + +Examples: + pastebin 'My example pastebin title' + pastebin 'My example pastebin title' - < file + cat file | pastebin 'My example pastebin title' - +EOF +} + +FULL_TITLE="${1:-}" +[ -z "$FULL_TITLE" ] && { + usage 'FULL_TITLE' + 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;' +} + +SLUG_TITLE="$(slugify "$FULL_TITLE")" +PASTE_DATE="$(date -I)" +OUT="_pastebins/$PASTE_DATE-$SLUG_TITLE.md" +if [ -n "${2:-}" ]; then + shift + CONTENT=$(cat "$@") +else + CONTENT='FIXME' +fi + +cd ~/dev/libre/website > /dev/null + +[ -f "$OUT" ] && { + echo "Pastebin named $OUT already exists." + exit 1 +} + +cat < "$OUT" +--- + +title: ${FULL_TITLE} + +date: ${PASTE_DATE} + +layout: post + +lang: en + +ref: $SLUG_TITLE + +--- + +\`\`\`FIXME +$CONTENT +\`\`\` +EOF + +git reset . +git add "$OUT" +git commit -m "$0: Auto-add $OUT" +make clean publish +open "https://euandre.org/pastebin/$(echo "$PASTE_DATE" | tr '-' '/')/$SLUG_TITLE.html" +cd - > /dev/null diff --git a/scripts/pastebin.sh b/scripts/pastebin.sh deleted file mode 100755 index d306f878..00000000 --- a/scripts/pastebin.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh -set -eu - -usage() { - cat <. - -Usage: - pastebin.sh [-|FILE] - - Reads contents from [FILE], from stdin if '-' is given, and opens the - editor on the content. - - Arguments: - FULL_TITLE Full title of the pastebin - -Examples: - pastebin.sh 'My example pastebin title' - pastebin.sh 'My example pastebin title' - < file - cat file | pastebin.sh 'My example pastebin title' - -EOF -} - -FULL_TITLE="${1:-}" -[ -z "$FULL_TITLE" ] && { - usage 'FULL_TITLE' - 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;' -} - -SLUG_TITLE="$(slugify "$FULL_TITLE")" -PASTE_DATE="$(date -I)" -OUT="_pastebins/$PASTE_DATE-$SLUG_TITLE.md" -if [ -n "${2:-}" ]; then - shift - CONTENT=$(cat "$@") -else - CONTENT='FIXME' -fi - -cd ~/dev/libre/website > /dev/null - -[ -f "$OUT" ] && { - echo "Pastebin named $OUT already exists." - exit 1 -} - -cat < "$OUT" ---- - -title: ${FULL_TITLE} - -date: ${PASTE_DATE} - -layout: post - -lang: en - -ref: $SLUG_TITLE - ---- - -\`\`\`FIXME -$CONTENT -\`\`\` -EOF - -git reset . -git add "$OUT" -git commit -m "$0: Auto-add $OUT" -make publish -open "https://euandre.org/pastebin/$(echo "$PASTE_DATE" | tr '-' '/')/$SLUG_TITLE.html" -cd - > /dev/null -- cgit v1.3