aboutsummaryrefslogtreecommitdiff
path: root/phlogthis
blob: 51df9dcd65391544724974c30e884bd1d7195580 (plain)
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
#!/usr/bin/env bash

# create phlog entry
# requires the text formating utility 'par'
# see https://git.wittamore.com/par/tree

# config
root="$HOME/src/gopher/phlog"
remoteroot="/srv/gopher/phlog"
editor="micro +1:1"
mkremotedir="ssh spike mkdir"

# save location
pushd "$(pwd)" || exit 

mkdir -p "$HOME/.tmp"
cd "$HOME/.tmp" || exit
editfile="phlogtmp.txt"
articledate="$(date -R)"
filedate="$(date +%Y-%m-%d-%H-%I)"
article="/tmp/gophermap.tmp"

read -rp "Enter title: " title

filetitle=$(echo "$title" | sed "s/ /-/g" | sed "s/[^A-Za-z0-9._-]//g")
dirname="$filedate-$filetitle"

# make local dir
mkdir "$root/$dirname"

# edit text
eval "$editor $editfile"

# Justify article. This may fail if a 
# non-empty line doesn't contain spaces
cat "$editfile" | par -jw67 > $article || cat "$editfile" > $article

header="$title\n$articledate\n+$(printf "%*s" 65 | tr " " "-")+\n\n"
sed -i "1s/^/$header/" $article

dest="$root/$dirname/gophermap"
mv "$article" "$dest"
rm $editfile

clear
cat "$dest"

echo "--------------------------"
read -rp "Do you want to correct this text? : " choix1

if [ "$choix1" != "n" ] ; then
    clear
	eval "$editor $dest"
fi

echo "Article saved as $dest"

echo "--------------------------"
read -rp "Make remote folder, run phlogmap & phlogrss & gosend? ; " choix2

if [ "$choix2" != "n" ] ; then
    echo "creating remote directory..."
    eval "$mkremotedir $remoteroot/$dirname"
    phlogmap; phlogrss ; gosend
fi

# return 
popd || exit

echo "Done."