blob: e12096bd08e4b7ac2bc9949c33424396d6824bc8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/bin/sh
set -eu
usage() {
red "Missing argument <${1}>.\n"
cat <<EOF
Usage:
pastebin.sh <FULL_TITLE> [-|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" ] && {
red "Pastebin named $OUT already exists."
exit 1
}
cat <<EOF | vipe | sponge > "$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"
"$(nix-build -A publishScript)/bin/publish.sh"
open "https://euandre.org/pastebin/$(echo "$PASTE_DATE" | tr '-' '/')/$SLUG_TITLE.html"
cd - > /dev/null
|