← Back to team overview

zim-wiki team mailing list archive

sharing: small shell script to stat word count in novel writing with zim

 

Hi,

I will probably share it on some website... But for now here it's:

Some times ago I written a small shell script which performs some stats useful for novel writer... Compatible Linux and mac OS probably. (windows too, but with extra stuff to have a working bash command line)

See attached document the code.
If it doesn't pass the mailing list config, I will paste it into a mail or upload it somewhere.

How to setup:

Drop the script in a funny location on your hard drive.

Make it executable
$ chmod a+x count_words.sh

Start a new Zim notebook for novel, Setup a top page for the novel chapter. Setup another page stats (or any funny name you used to) outside of the novel chapter folder. Mine looks like:

~/Notebooks/Novel$ tree
.
??? notebook.zim
??? Novel
?   ??? 01.chapter_1_a_dangerous_mission.txt
?   ??? 02._That_can_happen_to_you.txt
??? Novel.txt
??? Tool_pages
?   ??? stats.txt
??? Tool_pages.txt



The "Novel" folder will be used to group files together, each file is a chapter.

Test the script from command line (terminal)

$ cd /home/you/bin/or/funny_path/
$ ./count_words.sh /dev/stdout ~/Notebooks/Novel Novel
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4

samedi 3 mai 2014, 16:13:44 (UTC+0200)

nombre de mots (estimé de page 400 mots / page)

'''
0  ./01.chapter_1_a_dangerous_mission.txt  0  p.
5  ./02._That_can_happen_to_you.txt        0  p.
5  total                                   0  p.
'''

It works!

Yes it's French output. Edit the code to set your own message.
I could have translated... But... No.

Great continue with the custom tool now:

Tools > Custom Tools

Add.

Name: funny words stats
Description: Awesome tool to stat my progress about writing
Command: /home/you/bin/or/funny_path/count_words.sh %s %n Novel

"Novel" is the name of the "folder" top page holding the text file counted...
%s and %n are zim internal described in the form.

You can use "show in the toolbar" checkbox to have a button.

Be careful. Hitting the button will destroy the current page content replacing with the output above.

So use a dedicated stats page.

Have Fun! ;-)

Hope that helps.
Sylvain.

Attachment: count_words.sh
Description: application/shellscript


Follow ups