-
Notifications
You must be signed in to change notification settings - Fork 0
Scripting Plugins
So you want to start scripting your own plugins eh? Great! Before you start hacking away though, there’s a few things you should understand. A plugin for Lauf is essentially just a normal shell script. The only difference between a normal shell script and a Lauf plugin is that Lauf passes on information to it’s plugins by using shared functions and variables.
| Function / Variable | Name | Usage | Description |
|---|---|---|---|
Function |
yarra |
yarra "Variable Name" "String" |
Allows you to split a string into multiple variables. Basically a fake array or sorts. |
Function |
lauf_notify |
lauf_notify "Heading" "Body" |
Allows a plugin to notify the user information. |
Variable |
$lauf_exec |
$lauf_exec |
Holds what ever was typed into Lauf |
Variable |
$lauf_exec1 |
$lauf_exec1 |
Holds the command or plugin name being used |
Variable |
$lauf_exec2 - $lauf_exec999 |
everything else |
The next unlimited number of variables hold anything else typed into Lauf |
Open the [[Example Plugin|http://github.com/joshua-redfield/lauf/blob/testing/dev/example.sh]] and look over these instructions below.
First, let’s go over the heading comments. The best way to explain these comments is to explain to you how the core/plugins.sh works.
The 5th line of the comments is the plugin summary. This should tell the user what your plugin does. core/plugins.sh pulls this information using summ=$(head -n5 $test | tail -n1 | tr -d '#') . Head is grabbing the first 5 lines, tail grabbing just the last line of those 5 lines and tr is just removing the comment character.
The 7th line is the usage, This should tell the user the usage of your plugin(plugin arguments). core/plugin.sh pull this information using usage=$(head -n7 $test | tail -n1 | tr -d '#'). Works the same way as above.
The 9th line is the dependencies, This should tell the user what programs your script needs to function. core/plugin.sh pulls this information using depends=$(head -n9 $test | tail -n1 | tr -d '#'). Works same the same way.
Note: This means you can’t split these comments into multiple lines, they must be kept on their special line.
The next thing we’ll be covering is using the $lauf_exec1…$lauf_exec999 variables. These variables do nothing more than hold what was typed into Lauf. Which gives you the option of having arguments in your plugins. For example typing the following into Lauf: help with plugin open
Would turn into:
$lauf_exec1=help
$lauf_exec2=with
$lauf_exec3=plugin
$lauf_exec4=open
This is how you’ll be checking [[arguements|https://github.com/joshua-redfield/lauf/blob/testing/dev/example.sh#L13]] with your plugins.
When using the shell built-in: test and [ this is also a test statement ] against the $lauf_exec1…$lauf_exec999 vars you’ll often get an error message if the variable you are using the test statement against is a empty / unset. In order to stop this from happening you should use [[parameter expansion|https://github.com/joshua-redfield/lauf/blob/testing/dev/example.sh#L13]].
| Variable | Description |
|---|---|
$lauf_app_dir |
The directory where Lauf currently resides in |
$lauf_app_icon |
Location of where Lauf’s icon is located |
$lauf_version |
Version information |
$lauf_app_name |
Lauf’s application name |
$lauf_app_motto |
Lauf’s slogan |
$lauf_core_dir |
Location of core plugins |
$lauf_plugin_dir |
Location of external plugins |
$lauf_app_options |
General Lauf options, Allows plugins to grab information from lauf.cfg |