From 9b3cd2462a48ca942309e24f511db2ea1fddc95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 21 Mar 2016 22:21:02 +0100 Subject: vis: also lookup Lua support files relative to the binary location This simplifies deployment of vis on remote systems without root access. The idea is to extract a statically linked binary together with the lexer syntax files into some directory, adjust $PATH to include it and have everything just work. For now this uses /proc/self/exe and thus only works on Linux based systems. --- vis-lua.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'vis-lua.c') diff --git a/vis-lua.c b/vis-lua.c index 35dbe95..c25f64d 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include #include @@ -823,6 +826,7 @@ void vis_lua_start(Vis *vis) { /* extends lua's package.path with: * - $VIS_PATH/{,lexers} + * - {,lexers} relative to the binary location * - $XDG_CONFIG_HOME/vis/{,lexers} (defaulting to $HOME/.config/vis/{,lexers}) * - /usr/local/share/vis/{,lexers} * - /usr/share/vis/{,lexers} @@ -841,6 +845,19 @@ void vis_lua_start(Vis *vis) { paths++; } + char exe[PATH_MAX]; + ssize_t len = readlink("/proc/self/exe", exe, sizeof(exe)-1); + if (len > 0) { + exe[len] = '\0'; + char *exe_path = dirname(exe); + lua_pushstring(L, exe_path); + lua_pushstring(L, "/?.lua;"); + lua_pushstring(L, exe_path); + lua_pushstring(L, "/lexers/?.lua;"); + lua_concat(L, 4); + paths++; + } + /* try to get users home directory */ const char *home = getenv("HOME"); if (!home || !*home) { -- cgit v1.2.3