Execute G'MIC codes outside of user.gmic and updatexxxx.gmic. (Brief Tutorial)

Some of you may have already figured it out, but I’ll just be leaving a tutorial regardless. Let’s say you want to execute a .gmic file outside of those while you’re in the directory via cli.

First, copy and paste this code in user.gmic:

execute_gmic_file:
"$1" __main__

Then, in your local .gmic file, do the same, but with this code only:

__main__:
echo Hi

Execute your local gmic file in CLI by copy and pasting, then run it:

$ execute_gmic_file my_local_file.gmic
[gmic]./ Start G'MIC interpreter (v.3.3.3).
Hi
[gmic]./ End G'MIC interpreter.

What happened is that your user.gmic code calls __main__ command which was imported. Now, you know how to call G’MIC codes outside of the typical location. So, if you need to process files or even have a separate .gmic repository which doesn’t serve much use to end users, you can do this instead.

Use cases:

  1. Creating temporary scripts for processing files.
  2. Having a list of script codes to test for output
  3. Having a list of scripts that usually is out of scope for image-processing, and it’s just for you.

EDIT:

There’s also this as a option:

$ "my_local_file.gmic" __main__

And you can also use this for execute_gmic_file instead:

execute_gmic_file:
skip "${1=}
"main.gmic" __main__ $*

This option saves you from having to write out filename and allows for user parameters.

This gives me a idea of what G’MIC should do. Upon importing G’MIC file, search for __main__ or even commands that starts and ends with __ and immediately run it, otherwise, do nothing.