clp

command line syntax highlighter
git clone git://jeskin.net/clp.git
README | Log | Files | Refs | LICENSE

commit 62aea76fa2a8b8340e21518513db9e8ce9da2321
parent 88e7d0df0aded158e476ff3de86e843154d007a1
Author: Jon Eskin <eskinjp@gmail.com>
Date:   Thu, 14 Jul 2022 04:42:36 -0400

Document available filetype overrides

Diffstat:
Mclp.c | 25+++++++++++++++++++------
Mlua/clp.lua | 7+++++++
Mman/clp.1 | 14+++++++++-----
3 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/clp.c b/clp.c @@ -87,6 +87,7 @@ static bool package_exists(lua_State *L, const char *name) { int main(int argc, char *argv[]) { struct optparse_long longopts[] = { {"override-filetype", 't', OPTPARSE_REQUIRED}, + {"list-overrides", 'l', OPTPARSE_NONE}, {0}}; lua_State *L = luaL_newstate(); @@ -134,26 +135,38 @@ int main(int argc, char *argv[]) { lua_newtable(L); int option = 0; - char *filename; - char *filetype_override; + char *filename = ""; + char *filetype_override = ""; struct optparse options; optparse_init(&options, argv); while ((option = optparse_long(&options, longopts, NULL)) != -1) { switch (option) { + case 'l': + lua_getglobal(L, "print_available_overrides"); + ret = lua_pcall(L, 0, 0, 0); + if (ret != 0) { + fprintf(stderr, "%s\n", lua_tostring(L, -1)); + return 1; + } + lua_close(L); + return 0; case 't': - lua_pushliteral(L, "filetype_override"); filetype_override = options.optarg; - lua_pushstring(L, filetype_override); - lua_settable(L, -3); break; } } + if(!(strlen(filetype_override) == 0)) { + lua_pushliteral(L, "filetype_override"); + lua_pushstring(L, filetype_override); + lua_settable(L, -3); + } + filename = optparse_arg(&options); if (!filename) { - printf("Usage: clp [--filetype_override] file\n"); + printf("Usage: clp [options] file\n"); return 1; } lua_pushliteral(L, "filename"); diff --git a/lua/clp.lua b/lua/clp.lua @@ -51,4 +51,11 @@ function write(args) file:close() end +function print_available_overrides() + print('Available overrides:') + for lang, _ in pairs(ftdetect.filetypes) do + print('- ' .. lang) + end +end + return clp diff --git a/man/clp.1 b/man/clp.1 @@ -3,14 +3,18 @@ clp \- print files to stdout with syntax highlighting .SH SYNOPSIS .B clp -[\fB\-t\fR \fIFILETYPE\fR] -[\fB\-\-override-filetype\fR \fIFILETYPE\fR] +[\fb\-t\fr \fifiletype\fr] +[\fb\-\-override-filetype\fr \fifiletype\fr] +[\fb\-l\fr] +[\fb\-\-list-overrides\fr] file .SH DESCRIPTION .B clp -reads an input file, determines its language from its filetype, and writes -it to stdout with syntax highlighting. +reads an input file, determines its language from its filetype, and writes it to stdout with syntax highlighting. .SH OPTIONS .TP +.BR \-l ", " \-\-list-overrides +See below. +.TP .BR \-t ", " \-\-override-filetype=\fIFILETYPE\fR -Force a language's syntax for highlighting the file +Force a language's syntax for highlighting the file. To see available filetypes, run \fBclp \-\-list\-overrides\fR\