Installing Gems And Node Modules With Zplugin

With use of the  bin-gem-node annex you can install Ruby Gems and Node modules in an interesting way:

This has several benefits. For example, no $PATH alteration is required in the .zprofile file. Also, the package will be automatically updated on zplugin update. Plus, the installation will be isolated from other packages – multiple packages not be put in a single place.

An example Zplugin invocation that installs the remark tool that can be used to convert Markdown documents into man pages:

zplugin ice wait'2' lucid id-as'remark' node'remark <- !remark-cli; remark-man'
zplugin snippet /dev/null

It is snippet-based. An example plugin-based invocation:

zplugin ice wait'2' lucid id-as'remark' node'remark <- !remark-cli; remark-man'
zplugin load zdharma/null

It has an advantage – it will delete the remark function when unloading the plugin.

The exclamation-mark before !remark-cli is important – it causes the automatic function invoking the binary to be created. More information can be found on the bin-gem-node annex page.

The command installs 2 node modules – remark-cli and remark-man (the backend for the remark converter – remark can convert also to other formats). By using the exclamation-mark and the <- pointer it also requests the function that will run the remark binary to be created. The function has the following body:

remark () {
	local bindir="/root/.zplugin/plugins/remark/node_modules/.bin"
        local -x NODE_PATH="/root/.zplugin/plugins/remark2"/node_modules
        "$bindir"/"remark" "$@"
}

As it can be seen it ultimately provides the remark tool to the command line.