Automatically Pushing pet Snippets to an Existing git Repository

By chimo on (updated on )

I recently started using `pet` as a snippet manager (thanks to Thiago Perrotta’s excellent blog post).

It stores the snippets to a text file (`~/.config/pet/snippet.toml` by default) which makes it easy to copy/sync/version/etc. It natively supports synchronizing the snippet file as a GitHub Gist or GitLab Snippet (manually or automatically).

I’m already keeping my dotfiles in a git repo, however, and would like to keep my snippet.toml file in the same spot as everything else. I also don’t want to have to remember to manually push the changes every time I add/delete/edit something.

I run a lot of my applications in Incus containers (including `pet`) and have wrapper scripts in `~/.local/bin/` to run them.

So I modified my `pet.sh` wrapper script so that on every invocation, it:

  1. Runs `pet` like it’s meant to be used.
  2. Checks whether `snippet.toml` has local modifications.
  3. If so, prompt if we want to:
    1. See the diff.
    2. Commit the changes.
    3. Skip (do nothing).