There is already an add plugin (so we can't define that) but this simple plugin is instead called "plus" and shows how to use a filter with positional arguments to add two numbers (integers). You can watch an example here:
Or here are simple examples of how it works!
Add a number to what is passed to the filter.
Usage:
> plus {flags} <number>
flags:
--helpAdd two integers:
> echo 4 | plus 4
━━━━━━━━━━━
<unknown>
───────────
8
━━━━━━━━━━━Another!
> echo 4 | plus 4 | plus 4
12If you give the wrong type, no go!
> echo boo | plus 8
boo is not a numberCombine with other plugins too. Here is an example of listing files, getting the name, calculating the length, and adding 100 to it.
> ls | get name | len | plus 100
━━━┯━━━━━━━━━━━
# │ <unknown>
───┼───────────
0 │ 114
1 │ 108
2 │ 109
3 │ 109
4 │ 110
5 │ 121
━━━┷━━━━━━━━━━━If you want to run the plugin locally, you will nead nushell installed.
$ pip install nushellYou can then start nushell, and interact with the plugin. Make sure your present working directory with the file is added to the PATH. Here are some examples:
export PATH=$PWD:$PATH
$ nuAnd then proceed to interact with the plugin, as shown above.
Logs are printed to /tmp/nu_plugin_plus.log unless you set logging=False when
you initialize the plugin.
You can optionally build the container, doing a regular make will build a container with nu and the installed python modules:
make
# docker build -t vanessa/nu-plugin-plus .$ docker run -it vanessa/nu-plugin-plus
root@c7235d999a44:/code# nu
/code> help plusYou can also make a container with a standalone binary - we use pyinstaller to do this.
make standalone
$ docker run -it vanessa/nu-plugin-plusAnd execution proceeds as before. We can prove that we don't need the modules anymore because
the Dockerfile.standalone does pip3 uninstall -y nushell and it still works.
Why might you want to do this? It will mean that your plugin is a single file (binary) and you don't
need to rely on modules elsewhere in the system. I suspect there are other ways to compile
python into a single binary (e.g., cython) but this was the first I tried, and fairly straight forward.
If you find a different or better way, please contribute to this code base!