First commit

This commit is contained in:
Gordon Grant-Stuart 2023-01-18 16:28:18 +00:00
parent 756deb2b37
commit 3f1e6da7bf
43 changed files with 627 additions and 1 deletions

29
.writing/atmo.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
SCRIPT_DIR=$(dirname $(realpath $0))
BG_DIR="${SCRIPT_DIR/\/.writing/}/backgrounds"
while [[ $chosen != 'chosen' ]]; do
clear
echo -e "============================================\033[1;38;5;94m"
ls $BG_DIR
echo -e "\033[38;5;95m============================================"
cd $BG_DIR
read -e -p " Choose a background:$(echo -e "\033[1;38;5;94m") " bg
if [[ -e "$bg" && "$bg" =~ \.(jpg|jpeg)$ ]]; then
echo
$SCRIPT_DIR/viu "$bg" -w64
echo
read -sn1 -p "This one? [Y|n]" yn
if [[ ! ${yn^^} == 'N' ]]; then
rm -f $SCRIPT_DIR/backgrounds/atmo.jpg
ln -s "$(realpath "$bg")" $SCRIPT_DIR/backgrounds/atmo.jpg
chosen='chosen'
fi
echo
else
echo Not a .jpg
fi
done

View File

@ -0,0 +1 @@
/home/ggstuart/Code/Books/.Books/backgrounds/night-trains.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 874 KiB

100
.writing/compile.sh Executable file
View File

@ -0,0 +1,100 @@
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname $(realpath $0))
WRITING_DIR=${SCRIPT_DIR/\/.writing/}
####### defaults #########
YAML=$SCRIPT_DIR/frontmatter.yml
OUTPUT_FORMAT=docx
TEMPLATE=md2long.sh
SCENE_BREAK="\n\n### #\n\n"
LINE_BREAK="\n"
####### options #########
while getopts "hy:esf:" opt; do
case $opt in
y) YAML=$OPTARG ;;
e) OUTPUT_FORMAT=epub ;;
s) TEMPLATE=md2short.sh ;;
f) OUTPUT_FORMAT=$OPTARG ;;
h) echo "USAGE: compile [-y frontmatter.yml ] [ -e | -f format ] FILE.msk" ;;
esac
done
shift $((OPTIND-1))
msk=$1
echo -e "*********** compiling *******************\033[19D$msk "
chapter() {
dir=$1
if [[ $(egrep -c "^compile: *0$" $dir/folder.txt) -eq 0 ]]; then
chaptitle=$(cat $dir/folder.txt | egrep "^title:" | sed 's/^title: *//g')
chapsubtitle=$(cat $dir/folder.txt | egrep "^summarySentence:" | sed 's/^summarySentence: *//g')
echo "# $chaptitle - $chapsubtitle"
for md in $dir/*.md; do
if [[ $(egrep -c "^compile: *0$" $md) -eq 0 ]]; then
start=$(( $(egrep -n -m1 '^$' $md | cut -d: -f1) + 2 ))
echo >> $md
tail -n +$start $md | while read line; do echo "$line"; echo -ne $LINE_BREAK; done
echo -ne $SCENE_BREAK
fi
done
fi
}
dir2md() {
shortbooktitle=$(cat $1/infos.txt | egrep "^Title:" | sed 's/^Title: *//g')
booktitle=$(cat $1/infos.txt | egrep "^Subtitle:" | sed 's/^Subtitle: *//g')
compiled_md=$(mktemp /tmp/XXXXXXXX.md)
cat $YAML | sed "s/^title:\ .*$/title: \"$shortbooktitle\"/g; s/^short_title:\ .*$/short_title: \"$shortbooktitle\"/g" > $compiled_md
for dir in $1/outline/*; do
if [[ -d $dir ]]; then
chapter $dir >> $compiled_md
fi
done
echo "*********** markdown compiled ***********"
}
compile() {
if [[ -f $msk ]]; then
if [[ $(cat $msk | wc -c) -eq 1 ]]; then
dir2md ${msk%\.*}
else
#unzip the msk
unzipped_dir=$(mktemp -d /tmp/XXXXXXXX)
unzip -qou "$msk" -d $unzipped_dir
dir2md $unzipped_dir
rm -rf $unzipped_dir
fi
elif [[ -d $msk && -f $msk/infos.txt ]]; then
dir2md $msk
else
echo No book specified
exit
fi
}
###### main ###########
case $OUTPUT_FORMAT in
docx)
compile
echo -en "\033[1;38;5;94m"
$SCRIPT_DIR/pandoc-templates/bin/$TEMPLATE --output "$booktitle.$OUTPUT_FORMAT" --overwrite $compiled_md #&> /dev/null
;;
epub)
compile
echo -en "\033[1;38;5;94m"
pandoc --from=markdown --to=epub --css=$SCRIPT_DIR/epub.css --output="$booktitle.$OUTPUT_FORMAT" --toc $compiled_md #&> /dev/null
;;
*)
echo -e "What on Earth is a \033[1m$OUTPUT_FORMAT\033[0m?"
echo "******* exiting because of reasons ******"
exit 1
;;
esac
echo -en "\033[1;38;5;95m"
echo "*********** pandoc finished *************"
rm $compiled_md
# echo $compiled_md
# echo $unzipped_dir
echo -e "\n\033[1m$booktitle.$OUTPUT_FORMAT\033[0m\n"

9
.writing/download.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname $(realpath $0))
WRITING_DIR=${SCRIPT_DIR/\/.writing/}
[[ ! -e $SCRIPT_DIR/initted ]] && $WRITING_DIR/init.sh
[[ ! -e $WRITING_DIR/backgrounds ]] && ln -s "$SCRIPT_DIR/backgrounds" "$WRITING_DIR/backgrounds"
cd $WRITING_DIR && git pull

54
.writing/epub.css Normal file
View File

@ -0,0 +1,54 @@
/* kindle friendly css with indents*/
body {
line-height: 1.75;
}
body * {
line-height: inherit;
}
p {
margin: 0rem 0% 0rem 0rem;
text-indent: 1rem;
}
h1+p, h2+p {
text-indent: 0em;
}
h1, h2, .author {
text-align: center;
}
h4, h5 {
font-size: 100%;
}
blockquote {
font-size: 90%;
color: #666666;
margin: 0;
padding: 1em 0 1em 3em;
border-left: 0.25em #EEE solid;
}
blockquote>p {
text-indent: 0em;
}
hr {
height: 0;
margin-top: 1em;
margin-bottom: 1em;
border: 0;
border-top: 1px solid #eee;
}
/*suppress numbering in TOC to match the default pandoc styling*/
ol.toc li {
list-style-type: none;
margin: 0;
padding: 0;
}

11
.writing/frontmatter.yml Normal file
View File

@ -0,0 +1,11 @@
---
title: "MANAGED BY SCRIPT - 'Subtitle' field in Manuskript"
short_title: "MANAGED BY SCRIPT - 'Title' field in Manuskript"
author: "by Sherlock Holmes"
author_lastname: "Holmes"
contact_name: "Sherlock Holmes"
contact_address: "221B Baker Street"
contact_city_state_zip: "Marylebone, London, NW1 6XE"
contact_phone: "(+44) 02222 123456"
contact_email: "holmes@mod.gov.uk"
---

5
.writing/history Normal file
View File

@ -0,0 +1,5 @@
download
upload
compile
atmo
manuskript

1
.writing/local.d/readme Normal file
View File

@ -0,0 +1 @@
This folder is for storing local scripts that don't get synced

View File

@ -0,0 +1,40 @@
[General]
Name=Atmosphere
[Background]
Color=#000000
ImageFile=atmo.jpg
Type=3
[Foreground]
Color=#ffffff
Margin=40
Opacity=85
Padding=20
Position=1
Rounding=8
RoundingDisabled=0
Width=650
[ForegroundBlur]
Enabled=true
Radius=32
[ForegroundShadow]
Color=#000000
Enabled=true
Offset=2
Radius=16
[Spacings]
Alignment=0
IndentFirstLine=true
LineSpacing=150
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#2e3436
Font="DejaVu Serif,14,-1,5,50,0,0,0,0,0"
Misspelled=#ff0000

View File

@ -0,0 +1,40 @@
[General]
LoadColor=#a8bacc
Name="Gentle Blues"
[Background]
Color=#a8bacc
ImageFile=
Type=0
[Foreground]
Color=#a8bacc
Margin=65
Opacity=0
Padding=10
Position=1
Rounding=0
RoundingDisabled=10
Width=700
[ForegroundBlur]
Enabled=false
Radius=32
[ForegroundShadow]
Color=#000000
Enabled=false
Offset=2
Radius=8
[Spacings]
IndentFirstLine=false
LineSpacing=100
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#2d3f56
Font="Times New Roman,12,-1,5,50,0,0,0,0,0"
Misspelled=#ff0000

View File

@ -0,0 +1,39 @@
[General]
LoadColor=#000000
[Background]
Color=#000000
ImageFile=
Type=0
[Foreground]
Color=#000000
Margin=65
Opacity=0
Padding=10
Position=1
Rounding=0
RoundingDisabled=10
Width=700
[ForegroundBlur]
Enabled=false
Radius=32
[ForegroundShadow]
Color=#000000
Enabled=false
Offset=2
Radius=8
[Spacings]
IndentFirstLine=false
LineSpacing=100
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#0cf155
Font="Courier New,12,-1,5,50,0,0,0,0,0"
Misspelled=#0d5322

View File

@ -0,0 +1,37 @@
The regular early morning yell of horror was the sound of Arthur Dent waking up and suddenly remembering where he was.
It wasn't just that the cave was cold, it wasn't just that it was damp and smelly. It was the fact that the cave was in the middle of Islington and there wasn't a bus due for two million years.
Time is the worst place, so to speak, to get lost in, as Arthur Dent could testify, having been lost in both time and space a good deal. At least being lost in space kept you busy.
He was stranded in prehistoric Earth as the result of a complex sequence of events which had involved him being alternately blown up and insulted in more bizarre regions of the Galaxy than he ever dreamt existed, and though his life had now turned very, very, very quiet, he was still feeling jumpy.
He hadn't been blown up now for five years.
Since he had hardly seen anyone since he and Ford Prefect had parted company four years previously, he hadn't been insulted in all that time either.
Except just once.
It had happened on a spring evening about two years previously.
He was returning to his cave just a little after dusk when he became aware of lights flashing eerily through the clouds. He turned and stared, with hope suddenly clambering through his heart. Rescue. Escape. The castaway's impossible dream --- a ship.
And as he watched, as he stared in wonder and excitement, a long silver ship descended through the warm evening air, quietly, without fuss, its long legs unlocking in a smooth ballet of technology.
It alighted gently on the ground, and what little hum it had generated died away, as if lulled by the evening calm.
A ramp extended itself.
Light streamed out.
A tall figure appeared silhouetted in the hatchway. It walked down the ramp and stood in front of Arthur.
"You're a jerk, Dent," it said simply.
It was alien, very alien. It had a peculiar alien tallness, a peculiar alien flattened head, peculiar slitty little alien eyes, extravagantly draped golden ropes with a peculiarly alien collar design, and pale grey-green alien skin which had about it that lustrous shine which most grey-green faces can only acquire with plenty of exercise and very expensive soap.
Arthur boggled at it.
It gazed levelly at him.
Arthur's first sensations of hope and trepidation had instantly been overwhelmed by astonishment, and all sorts of thoughts were battling for the use of his vocal chords at this moment.
"Whh ...?" he said.
"Bu ... hu ... uh ..." he added.
"Ru ... ra ... wah ... who?" he managed finally to say and lapsed into a frantic kind of silence. He was feeling the effects of having not said anything to anybody for as long as he could remember.
The alien creature frowned briefly and consulted what appeared to be some species of clipboard which he was holding in his thin and spindly alien hand.
"Arthur Dent?" it said.
Arthur nodded helplessly.
"Arthur Philip Dent?" pursued the alien in a kind of efficient yap.
"Er ... er ... yes ... er ... er," confirmed Arthur.
"You're a jerk," repeated the alien, "a complete asshole."
"Er ..."
The creature nodded to itself, made a peculiar alien tick on its clipboard and turned briskly back towards the ship.
"Er ..." said Arthur desperately, "er ..."
"Don't give me that!" snapped the alien. It marched up the ramp, through the hatchway and disappeared into the ship. The ship sealed itself. It started to make a low throbbing hum.
"Er, hey!" shouted Arthur, and started to run helplessly towards it.
"Wait a minute!" he called. "What is this? What? Wait a minute!"
The ship rose, as if shedding its weight like a cloak to the ground, and hovered briefly. It swept strangely up into the evening sky. It passed up through the clouds, illuminating them briefly, and then was gone, leaving Arthur alone in an immensity of land dancing a helplessly tiny little dance.
"What?" he screamed. "What? What? Hey, what? Come back here and say that!"
He jumped and danced until his legs trembled, and shouted till his lungs rasped. There was no answer from anyone. There was no one to hear him or speak to him.

View File

@ -0,0 +1,39 @@
[General]
LoadColor=#5d3e3d
[Background]
Color=#000000
ImageFile=spacedreams.jpg
Type=5
[Foreground]
Color=#beaf9b
Margin=65
Opacity=50
Padding=10
Position=1
Rounding=10
RoundingDisabled=0
Width=700
[ForegroundBlur]
Enabled=true
Radius=32
[ForegroundShadow]
Color=#000000
Enabled=true
Offset=2
Radius=16
[Spacings]
IndentFirstLine=false
LineSpacing=100
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#000000
Font="Times New Roman,12,-1,5,50,0,0,0,0,0"
Misspelled=#ff0000

View File

@ -0,0 +1,29 @@
[General]
Name=Wei Long
[Background]
Color=#000000
ImageFile=kowloon3.jpg
Type=3
[Foreground]
Color=#ffffff
Margin=40
Opacity=75
Padding=10
Position=1
Rounding=5
Width=900
[Spacings]
Alignment=0
IndentFirstLine=true
LineSpacing=150
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#2e3436
Font="DejaVu Serif,14,-1,5,50,0,0,0,0,0"
Misspelled=#ff0000

View File

@ -0,0 +1,39 @@
[General]
LoadColor=#985a20
[Background]
Color=#985a20
ImageFile=writingdesk.jpg
Type=5
[Foreground]
Color=#fffdf6
Margin=65
Opacity=100
Padding=10
Position=1
Rounding=0
RoundingDisabled=10
Width=700
[ForegroundBlur]
Enabled=false
Radius=32
[ForegroundShadow]
Color=#000000
Enabled=true
Offset=1
Radius=4
[Spacings]
IndentFirstLine=false
LineSpacing=100
ParagraphAbove=0
ParagraphBelow=0
TabWidth=48
[Text]
Color=#000000
Font="Times New Roman,12,-1,5,50,0,0,0,0,0"
Misspelled=#ff0000

12
.writing/upload.sh Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname $(realpath $0))
WRITING_DIR=${SCRIPT_DIR/\/.writing/}
cd $WRITING_DIR && git add .
git commit -m "Saved at $(date) from $(hostname)"
git push
if [[ -e "$SCRIPT_DIR/local.d/postupload.sh" ]]; then
$SCRIPT_DIR/local.d/postupload.sh
fi

3
.writing/write.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
screen -d -m nohup $MANUSKRIPT_BIN &>/dev/null &

26
.writing/writingenv.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# This script should be sourced
WRITING_DIR=$1
SCRIPT_DIR="$WRITING_DIR/.writing"
lightbrown="\[\033[1;38;5;94m\]"
darkbrown="\[\033[38;5;95m\]"
export MANUSKRIPT_BIN="$SCRIPT_DIR/manuskript/bin/manuskript"
alias upload="$SCRIPT_DIR/upload.sh"
alias download="$SCRIPT_DIR/download.sh"
# alias write="$SCRIPT_DIR/write.sh"
# alias wryte="$SCRIPT_DIR/write.sh"
alias manuskript="$SCRIPT_DIR/write.sh"
alias atmo="$SCRIPT_DIR/atmo.sh"
alias compile="$SCRIPT_DIR/compile.sh"
bookmoji=$(echo -e "\U1F4D6")
PS1=$(echo -e "$bookmoji $lightbrown.writing-\[\033[0m\] $darkbrown")
which guake &>/dev/null && guake -r $bookmoji # Just in case you use guake
history -c
history -r "$SCRIPT_DIR/history"
cd $WRITING_DIR
clear

View File

@ -1,3 +1,20 @@
# writing
A writing environment that makes Manuskript easier.
### A writing environment that make using Manuskript easier. Also, there's other stuff.
Run `init.sh` to install everything. This will install:
- Manuskript
- Pandoc
- LanguageTool
- Prosegrinder pandoc templates
You can activate the environment in the terminal with the command `writing`. This will let you use the following commands:
- **manuskript** or **msk** : Open Manuskript.
- **atmo** : Choose the background image for the "atmosphere" full-screen theme in Manuskript.
- **compile** : Compile a Manuskript project to epub or docx (using the Shunn manuscript format).
- **upload** and **download** : Use git to back up your writing to a remote server.
You can make the following changes:
- `.writing/frontmatter.yml` : Your author details, for your compiled projects.
- `backgrounds` : Copy any background images for your atmo theme (must be jpegs)

95
init.sh Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env bash
SCRIPT_DIR=$(dirname $(realpath $0))
lightbrown="\033[1;38;5;94m"
darkbrown="\033[38;5;95m"
echo -e "$lightbrown 📚 running the Writing! init script 📚 $darkbrown"
al="alias writing=\". $SCRIPT_DIR/.writing/writingenv.sh $SCRIPT_DIR\""
if [[ $(grep -c "$al" ~/.bash_aliases) -eq 0 ]]; then
echo $al >> ~/.bash_aliases
fi
if [[ $(grep -c "msk=1;38;5;95" ~/.bash_aliases) -eq 0 ]]; then
echo 'export LS_COLORS="$LS_COLORS:*.msk=1;38;5;95"' >> ~/.bash_aliases
fi
########## Install screen, git & pandoc #############
if type yum &>/dev/null; then
pac='yum'
elif type apt &>/dev/null; then
pac='apt'
else
echo -e "$darkbrown You're Linuxing wrong."
exit
fi
for i in git screen pandoc; do
type $i &>/dev/null || echo -e "$darkbrown Installing $i" && sudo $pac install -y $i
done
########## Install manuskript ###############
function reresource() {
rm -rf "$SCRIPT_DIR/.writing/manuskript/resources/$1"
ln -s "$SCRIPT_DIR/.writing/$1" "$SCRIPT_DIR/.writing/manuskript/resources/$1"
}
cd $SCRIPT_DIR/.writing && git clone https://github.com/olivierkes/manuskript.git
if [[ $? -ne 0 ]]; then
cd $SCRIPT_DIR/.writing/manuskript && git pull
fi
rm -rf "$SCRIPT_DIR/.writing/manuskript/sample-projects"
reresource themes
reresource backgrounds
reresource dictionaries
rm $SCRIPT_DIR/backgrounds
ln -s "$SCRIPT_DIR/.writing/backgrounds" "$SCRIPT_DIR/backgrounds"
################# Install Prosegrinder pandoc templates ############
echo -e "$darkbrown Installing Pandoc Templates"
cd $SCRIPT_DIR/.writing && git clone https://github.com/prosegrinder/pandoc-templates.git
if [[ $? -ne 0 ]]; then
cd $SCRIPT_DIR/.writing/pandoc-templates && git pull
fi
################# Install LanguageTool ############
echo -e "$darkbrown Installing LanguageTool"
sudo snap install languagetool
echo -e "$darkbrown Installing LanguageTool Python"
sudo pip install language_tool_python
################# Install viu ############
if [[ ! -e "$SCRIPT_DIR/.writing/viu" ]]; then
curl -o "$SCRIPT_DIR/.writing/viu" "https://github.com/atanunq/viu/releases/download/v1.4.0/viu" && chmod +x "$SCRIPT_DIR/.writing/viu"
fi
cd $SCRIPT_DIR/.writing
##################### Add the password to the git config
rou=$(git config --get remote.origin.url | sed 's$https://$$g')
if [[ $(echo $rou | egrep -c [^:]*:[^@]*@ ) -eq 0 ]]; then
echo -e '\n*******************************************************\n'
echo -n 'Enter the git username: '
read username
echo -n "Enter the git password for $username: "
stty -echo
read password
stty echo
newurl="https://$username:$password@$rou"
git config --replace-all remote.origin.url "$newurl"
echo
fi
touch $SCRIPT_DIR/.writing/initted