Skip to content

Instantly share code, notes, and snippets.

@losinggeneration
Last active December 15, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save losinggeneration/5246813 to your computer and use it in GitHub Desktop.
Save losinggeneration/5246813 to your computer and use it in GitHub Desktop.
Lua path setting with ZSH functions. This is another reason why ZSH is awesome: macro shell scripting. This removes the need to duplicate code for each of these functions.
# useful for when you have multiple lua commands for different versions
for i in lua lua5.2 lua5.1 luajit; do
function $i()
{
# Get Lua's version
local lua_version=$(command $0 -e "print(string.sub(_VERSION, -3))")
# Append to Lua's paths using normal shell variable interpolation
LUA_PATH=$(command $0 -e "print(package.path..';$HOME/.luarocks/share/lua/$lua_version/?.lua;$HOME/.luarocks/share/lua/$lua_version/?/init.lua;$HOME/.local/share/lua/$lua_version/?.lua;$HOME/.local/share/lua/$lua_version/?/init.lua')") \
LUA_CPATH=$(command $0 -e "print(package.cpath..';$HOME/.luarocks/lib/lua/$lua_version/?.so;$HOME/.local/lib/lua/$lua_version/?.so')") \
command $0 $*
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment