#!/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 -p" mkdir -p "$root/$(date +%Y)" eval "$mkremotedir $remoteroot/$(date +%Y)" # 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="$HOME/.tmp/article.tmp" read -rp "Enter title: " title filetitle=$(echo "$title" | sed "s/ /-/g" | sed "s/[^A-Za-z0-9._-]//g") articlename="$filedate-$filetitle.txt" # 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/$(date +%Y)/$articlename" mv "$article" "$dest" echo -e "\n\n␌" >> "$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 "run phlogmap & phlogrss & gosend? ; " choix2 if [ "$choix2" != "n" ] ; then phlogmap; phlogrss ; gosend fi # return popd || exit echo "Done."