On Saturday, September 14, 2019 at 1:58:57 PM UTC-7, btheado wrote:
>
> I'm currently using leo as my main note-taking application and I find it 
> very useful to have auto-saving, so I enabled the auto-save module.
>
> I felt a little nervous about using auto-save and decided I wanted a git 
> commit on every save so I would have a history in case anything goes wrong.
>
>
> Hi Brian,

I have been using bash and fossil to do something similar.

I start Leo using a bash script.

#!/bin/bash

cd ~/leo-editor
git pull
cd /working/MEGA/leo-files
./rerun2 ./push &
python3 ~/leo-editor/launchLeo.py $1 $2 $3



I treat Leo as an abstraction layer that sits on top of my filesystem and 
all of my work in external files. I keep all of my .leo files under version 
control in the same directory. Every time I start a new session, I pull 
from git (pretty much always from git checkout devel).

I then change to the leo-files directory which becomes the working 
directory. I run rerun2 which is a bash script I found online that monitors 
all the files in the current directory and will run a command of my choice 
with every change. I run this detached and then run Leo. 

#!/usr/bin/env bash

# Events that occur within this time from an initial one are ignored
ignore_secs=0.25
clear='false'
verbose='false'

function usage {
    echo "Rerun a given command every time filesystem changes are detected."
    echo ""
    echo "Usage: $(basename $0) [OPTIONS] COMMAND"
    echo ""
    echo "  -c, --clear     Clear the screen before each execution of 
COMMAND."
    echo "  -v, --verbose   Print the name of the files that changed to 
cause"
    echo "                  each execution of COMMAND."
    echo "  -h, --help      Display this help and exit."
    echo ""
    echo "Run the given COMMAND, and then every time filesystem changes are"
    echo "detected in or below the current directory, run COMMAND again."
    echo "Changes within $ignore_secs seconds are grouped into one."
    echo ""
    echo "This is useful for running commands to regenerate visual output 
every"
    echo "time you hit [save] in your editor. For example, re-run tests, or"
    echo "refresh markdown or graphviz rendering."
    echo ""
    echo "COMMAND can only be a simple command, ie. \"executable arg 
arg...\"."
    echo "For compound commands, use:"
    echo ""
    echo "    rerun bash -c \"ls -l | grep ^d\""
    echo ""
    echo "Using this it's pretty easy to rig up ad-hoc GUI apps on the fly."
    echo "For example, every time you save a .dot file from the comfort of"
    echo "your favourite editor, rerun can execute GraphViz to render it to"
    echo "SVG, and refresh whatever GUI program you use to view that SVG."
    echo ""
    echo "COMMAND can't be a shell alias, and I don't understand why not."
}

while [ $# -gt 0 ]; do
    case "$1" in
      -c|--clear) clear='true';;
      -v|--verbose) verbose='true' ;;
      -h|--help) usage; exit;;
      *) break;;
    esac
    shift
done

function execute() {
    if [ $clear = "true" ]; then
        clear
    fi
    if [ $verbose = "true" ]; then
        if [ -n "$changes" ]; then
            echo -e "Changed: $(echo -e $changes | cut -d' ' -f2 | sort -u 
| tr '\n' ' ')"
            changes=""
        fi
        echo "$@"
    fi
    "$@"
}

execute "$@"
ignore_until=$(date +%s.%N)

inotifywait --quiet --recursive --monitor --format "%e %w%f" \
    --event modify --event move --event create --event delete \
    --exclude '__pycache__' --exclude '.cache' \
    . | while read changed
do

    changes="$changes\n$changed"

    if [ $(echo "$(date +%s.%N) > $ignore_until" | bc) -eq 1 ] ; then
        ignore_until=$(echo "$(date +%s.%N) + $ignore_secs" | bc)
        ( sleep $ignore_secs ; execute "$@" ) &
    fi

done

The push script is pretty straight forward and could be easily modified to 
use git instead of fossil.

#!/bin/bash

fossil add .
fossil commit . -m "Autocommit"

Since rerun2 is still part of the console session it closes when I close 
Leo which looks after having it hang around clutttering up the joint.

This might be a little tighter than the method you use.

Chris

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/3ba51137-7d24-404f-b5f9-c33859bc7aa6%40googlegroups.com.

Reply via email to