I need a real-time filesystem watcher that detects when any file in ~/.hermes/config/ changes, then immediately git add -A && git commit -m “auto: …” && git push.

Currently I’m running a cron job every midnight to batch it, but I’d rather have it trigger instantly. On Arch (btw) what’s the cleanest approach?

I’ve looked at:

  • incron — old, seems barely maintained
  • systemd path units — native, but feels heavyweight for one small folder
  • inotifywait in a loop — simple but fragile
  • entr — neat but needs something to kick off the initial watch

What would you actually use for a setup that needs to survive reboots and not eat CPU?

  • Shimitar@downonthestreet.eu
    link
    fedilink
    English
    arrow-up
    12
    ·
    1 day ago

    Inotify is the official kernel supported tool that uses the inotify API, again that is the official kernel API for monitoring files and folders.

    Its not that immediate to use, specially because there are caveats but works reliably well and indeed get the job done. Why do you say fragile? There isn’t a more comprehensive approach.

    Only issue, doesn’t work on NFS and Samba shares.

    • Eggymatrix@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      ·
      4 hours ago

      Greybeard dev here, just stepping by to say I would do the same, this works and does nothing weird if there is nothing to commit.

      I don’t know what the problem of the other crying person is, but robust IO watching should not be done in bash and whatever the fancy solution is it will not work as reliably as this.

      • I_Am_Jacks_____@sh.itjust.works
        link
        fedilink
        arrow-up
        7
        ·
        22 hours ago

        Before showing your terrible understanding of git, try it. If you run ‘git commit -m auto foo’ and foo has not changed, git will not do anything. It’s a no-op. So there is no downside and is very simple. Additionally, it returns 1, so if you do ‘git commit -m auto foo && git push’, it won’t do the push.

        But thanks for playing

  • Hund@feddit.nu
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    13 hours ago

    inotifywait in a loop? Why not something like this?

    inotifywait -m -r -e create,delete,modify,move /home/.hermes/config
    
  • Pika@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 day ago

    I second the inotifywait method. Thats currently how I look for new appimages and auto add them to my menus. You can tell it a directory like what you are looking for, and have it only trigger on new files, edited files and deleted files, then have it run an external script when it does.

  • Mio@feddit.nu
    link
    fedilink
    arrow-up
    1
    ·
    1 day ago

    INotify sounds best. Otherwise watch -n 10 git commit -am “auto” && git push. Git dont allow empty commits.