diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-21 22:21:02 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-21 22:41:27 +0100 |
| commit | 9b3cd2462a48ca942309e24f511db2ea1fddc95b (patch) | |
| tree | 009da77782848cfc8e6c1e83a49a0a1d7e6a08bb | |
| parent | 83b495b0c10f065897cc420a92afc7ac41448c26 (diff) | |
| download | vis-9b3cd2462a48ca942309e24f511db2ea1fddc95b.tar.gz vis-9b3cd2462a48ca942309e24f511db2ea1fddc95b.tar.xz | |
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.
| -rw-r--r-- | GNUmakefile | 3 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | lexers/README.md | 1 | ||||
| -rw-r--r-- | vis-lua.c | 17 | ||||
| -rw-r--r-- | vis.1 | 4 |
5 files changed, 23 insertions, 5 deletions
diff --git a/GNUmakefile b/GNUmakefile index f6e57d7..4773324 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -147,7 +147,7 @@ local: clean dependencies CFLAGS_TERMKEY= LDFLAGS_TERMKEY=-ltermkey \ CFLAGS_LUA="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL" \ LDFLAGS_LUA="-llua -lm -ldl" - @echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) VIS_PATH=. ./vis + @echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) ./vis standalone: clean dependency/sources/install-libmusl PATH=$(DEPS_BIN):$$PATH PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= $(MAKE) \ @@ -160,6 +160,5 @@ standalone: clean dependency/sources/install-libmusl LDFLAGS_LUA="-llua -lm -ldl" \ CONFIG_ACL=0 CFLAGS_ACL= LDFLAGS_ACL= \ CONFIG_SELINUX=0 CFLAGS_SELINUX= LDFLAGS_SELINUX= - @echo Run with: VIS_PATH=. ./vis .PHONY: standalone dependencies dependencies-full local
\ No newline at end of file @@ -47,8 +47,7 @@ In order to build vis you will need a C99 compiler as well as: Assuming these dependencies are met, execute: - $ ./configure && make - $ VIS_PATH=. ./vis config.h + $ ./configure && make && sudo make install By default the `configure` script will try to auto detect support for Lua. See `configure --help` for a list of supported options. You can diff --git a/lexers/README.md b/lexers/README.md index a7d25c2..34ca587 100644 --- a/lexers/README.md +++ b/lexers/README.md @@ -9,6 +9,7 @@ based lexers from the [Scintillua](http://foicica.com/scintillua/) project. Vis searches the lexers in the following locations: * `$VIS_PATH/lexers` + * `./lexers` relative to the binary location (using `/proc/self/exe`) * `$XDG_CONFIG_HOME/vis/lexers` * `/usr/local/share/vis/lexers` * `/usr/share/vis/lexers` @@ -1,6 +1,9 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <limits.h> +#include <unistd.h> +#include <libgen.h> #include <sys/types.h> #include <pwd.h> @@ -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) { @@ -24,7 +24,9 @@ Defaults (in this order) to: .RS .RS .TP -.B $XDG_CONFIG_HOME/vis +The location of the vis binary +.TP +.B $XDG_CONFIG_HOME/vis where .B $XDG_CONFIG_HOME refers to |
