Mepo has advanced scripting capabilities through mepolang by way of primarily two mechanisms: 1) via interactive scripting through STDIN and 2) via the shellpipe_{sync,async} mepolang mechanism from binding commands.
Mepo has the capability of being scripted interactively via
feeding mepolang commands continually into the application's STDIN
filedescriptor. This functionality can be enabled via using the -i
commandline flag which indicates to the application logic to continually
read commands from STDIN.
One example might be:
echo "prefset_n crosshair_size 200;" | mepo -i
Or continually:
mkfifo foo
cat foo | mepo -i &
echo "prefset_n crosshair_size 200;" > foo
Or to interactively debug similar to a REPL (note -e
enables debug messages):
tee | mepo -i -e
shellpipe_sync
/ shellpipe_async
Many commands for mepolang, and binding commands in particular accept a mepolang expression themselves to run, for example: bind_button, bind_key, and bind_gesture. Using these binding commands, in coordination with shellpipe_sync as your mepolang expression to run, you may bind a shellscript on a keybinding, clicking a button, or performing a gesture for example. This is done often in the default base configuration (which is a great example to study from), but may be done as well by end-users in their configuration as well.
The script or program to run for shellpipe_{sync,async}
may
be written in any language (though shellscript is simplest/best)
and the only requirement is your script needs to write mepolang
plain text to STDOUT. To make this more practical, for example,
to bind a keybinding for Control-j to set the crosshair size
sequentially to 3 different sizes, you might in your mepolang
configuration
write:
bind_key c j [shellpipe_sync crosshair.sh];
And then save in your $PATH
, the script crosshair.sh
as:
#!/usr/bin/env sh
echo "prefset_n crosshair_size 30;"
sleep 2
echo "prefset_n crosshair_size 100;"
sleep 2
echo "prefset_n crosshair_size 15;"
See the below tutorial or screencast for a more in-depth examples.
The following demo video example shows a full walkthrough
of creating a mepolang script from scratch and adding a UI
button to run the script via
bind_button
and shellpipe_sync
.
The following tutorial demonstrates an example script for a usecase where the user might want to select between three different locations to reposition the map to on pressing a keybinding.
As you will recall for shellpipe_sync
scripts, whatever appears in
STDOUT is run as mepolang. Accordingly the below script
simply prompts the user for a location using the mepo_ui_helper_menu.sh
helper script (which calls to zenity), and then as a result prints to
STDOUT via echo to use the prefset_n
mepolang command to set the picked
location's latitude and longitude.
#!/usr/bin/env sh
PLACES="NYC: 40.71273 -74.00602
Anchorage: 61.21631 -149.89485
Paris: 48.85889 2.32004"
PICKED="$(echo "$PLACES" | PROMPT="Location" mepo_ui_helper_menu.sh)"
LAT="$(echo "$PICKED" | cut -d ' ' -f2)"
LON="$(echo "$PICKED" | cut -d ' ' -f3)"
echo "prefset_n lat $LAT;"
echo "prefset_n lon $LON;"
Place the following above script in $PATH as mepo_ui_locationjump.sh
and then you can edit your config to run the
script via bind_key
for example as:
bind_key c j [shellpipe_sync locationjump.sh];
Or alternatively for quick testing, you could bootup mepo with this binding via:
echo "bind_key c j [shellpipe locationjump.sh];" | mepo -i
Either way now when you press Control-j the script will be run.