Shell scripts

Shell script user tools execute command entered in the Command text field using default user shell on Unix systems or cmd.exe on Windows.

Its input and output are specified by the following controls:

Shell script user tools have a number of environment variables set. APP_PID variable is set 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:

APP_PID

current process id.

DOC

document basename ("file.c" for file /home/user/file.c).

DOC_DIR

document directory ("/home/user" for file /home/user/file.c). Full file path is $DOC_DIR/$DOC.

DOC_BASE

basename without extension ("file" for file /home/user/file.c).

DOC_EXT

document filename extension including the period (".c" for file /home/user/file.c). Basename is always $DOC_BASE$DOC_EXT.

DOC_PATH

full document path.

LINE

1-based number of the line containing cursor. For example, if cursor is at the first line then LINE will be set to 1.

LINE0

0-based number of the line containing cursor. For example, if cursor is at the first line then LINE0 will be set to 0.

DATA_DIR

user data directory ($HOME/.local/share/medit-1/ on Unix systems).

INPUT_FILE

if input was set to "Document copy" then this is set to full path of the temporary file containing document text.

Additionally, all shell commands which run inside medit will have DATA_DIR/scripts directories in $PATH, so you may place some medit-specific programs or scripts into DATA_DIR/scripts/ to be used from shell script tools.