abra-code / OMC

OnMyCommand
http://www.abracode.com/free/cmworkshop/on_my_command.html
MIT License
33 stars 5 forks source link

Export all env variables #1

Closed abra-code closed 5 years ago

abra-code commented 5 years ago

Currently OMC engine scans the script to see which special environment variables are used and exports only these. This was meant to be perf optimization but it is premature optimization adding unnecessary complexity. If you have a script in the external file, OMC engine never scans it and you need to add the used env variables explicitly. The current idea is to always export all known env variables, which should not be expensive. This is especially important for the planned exe_script_file which would not contain the body of the script in the plist

abra-code commented 5 years ago

Upon closer look, there are some OMC env variables which trigger different functionality if they are present (nav dialogs, text input dialogs). They cannot be exported when not present and must be excluded. Also, a nib control variable to obtain the content from the whole table view is potentially costly and should be avoided (selected rows should be OK). There are also some variables rarely used and of lesser value which would incur unwanted cost to export them. With this in mind we can identify a core set of variables which will always be exported and will satisfy 99% of needs and leave out the rare/costly/dynamic ones. It would be an unfortunate inconsistency but I guess this is the best we can do. This is driven by pragmatic usage of OMC engine to simplify development. We should clearly document the "core" ones which are always exported.

abra-code commented 5 years ago

Initial set of changes for exporting core variables is submitted witth: https://github.com/abra-code/OMC/commit/d3484a6d3a12a1bb870617b841864b66cd3acea4

abra-code commented 5 years ago

This check-in completes the task: https://github.com/abra-code/OMC/commit/c794e5facc0013e0db6d22f5eb1c8c08ec368b0d

abra-code commented 5 years ago

Just to document the current state as of OMC 4.0 below is the list of always exported environment variables. All other environment variables while still supported are not automatically exported.

Always exported OMC env variables: OMC_OBJ_TEXT OMC_OBJ_PATH OMC_OMC_RESOURCES_PATH OMC_OMC_SUPPORT_PATH OMC_APP_BUNDLE_PATH OMC_NIB_DLG_GUID OMC_CURRENT_COMMAND_GUID OMC_NIB_DIALOG_CONTROL_N_VALUE (for all controls with IDs in the nib dialog) OMC_NIB_TABLE_N_COLUMN_M_VALUE (each column for each selected row in each table)

Notable exception not exported by default (rarely used and expensive to produce): OMC_NIB_TABLE_N_COLUMN_M_ALL_ROWS

Deprecated in OMC 4.0 and not exported by default: OMC_MY_HOST_BUNDLE_PATH (replaced by new OMC_APP_BUNDLE_PATH)