Previous: Storing tools in files, Up: User-defined tools


4.3 Shell scripts

In addition to the document text passed via standard input, shell scripts have a number of environment variables set. APP_PID variable is set to the current process process id, so that opening a file in the same instance of medit is as simple as medit filename (on the other hand, you will have to use command line options if you need to run a new medit instance). The following environment variables are set when scripts are executed:

DOC
the document basename.
DOC_DIR
the document file directory. The full file path is $DOC_DIR/$DOC.
DOC_BASE
the basename without extension.
DOC_EXT
the document filename extension including the period. The basename is always $DOC_BASE$DOC_EXT.
LINE
the number of the line containing cursor.
DATA_DIR
the user data directory. For example the tools are stored in $DATA_DIR/menu.cfg file and in files in the $DATA_DIR/tools/ directory.

Additionally, all processes ran from inside medit will have DATADIR/scripts directories in $PATH, so you may place some medit-specific programs or scripts into USERDATADIR/scripts/ to be used from shell script tools.