On Thu, Nov 19, 2020 at 05:46:00AM -0600, o1bigtenor wrote:
> Does anyone here have any ideas, or has already implemented, on how to
> save something from a text editor to multiple locations
> simultaneously? (Please)
I feel you need to think outside of the editor. That way you're also not
forced to switch your productive working environment.

Tools such as incron [1] permit automatic actions when some file is
changed. If you combined that with version control, you can have it
commit & optionally push on every change. The action MUST be smart about
the file having not changed since it was last saved.

In this case, run a script, using this incrontab configuration (this
should be a single line, in case your mail clients break it):
```
/home/user/ledger/ IN_CLOSE_WRITE,IN_MOVED_TO,dotdirs=false,recursive=true 
/home/user/bin/commit-ledger $@/$#
```

Every time a file under /home/user/ledger/ is written or a file is moved
into that same directory, the script will be called, with the full path
to that file as an argument. It won't fire on any files added under
dot-prefixes directories like /home/user/ledger/.git/

Example content for /home/user/bin/commit-ledger, untested:
```
#!/bin/bash
# Assumption: /home/user/ledger/ is a git repo that is initialized
cd /home/user/ledger/
pwd=$(pwd)
abspath=$1

# Remove the leading path
relpath=${abspath#${pwd}}

# Explicitly check if changed:
# git-status will generate output if the file is changed
# 'grep -sq .' will have exit code 1 if NO output is present.
git status --porcelain "${relpath}" |grep -sq . || exit 0

# Commit it:
git commit -q -m "Automated commit: $relpath" "${relpath}"

# Optional:
#git push ...

```

I personally wouldn't push on every commit, but instead have a cronjob
that tries to push to multiple locations (local directory on alternate
media, other servers) every 5 minutes. If there are no changes between
the remote side and the local side, it won't do anything.


[1] https://github.com/ar-/incron

-- 
Robin Hugh Johnson
Gentoo Linux: Dev, Infra Lead, Foundation Treasurer
E-Mail   : robb...@gentoo.org
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/robbat2-20201121T010943-694782569Z%40orbis-terrarum.net.

Attachment: signature.asc
Description: PGP signature

Reply via email to