[text_format] add shell script

pull/1235/head
Tim Stack 4 months ago
parent 36b68bfbff
commit 0f317c476d

@ -123,6 +123,8 @@ Features:
table that contains a JSON object with the top 5 values
for the fields extracted from the log message.
* Added Nextcloud log format from Adam Monsen.
* Added GitHub Event Log format for files from gharchive.org.
It makes a good example of a JSON-Lines format.
Bug Fixes:
* Binary data piped into stdin should now be treated the same

@ -67,6 +67,7 @@ detect_text_format(string_fragment sf,
static const auto MAKEFILE_STEM = ghc::filesystem::path("Makefile");
static const auto MD_EXT = ghc::filesystem::path(".md");
static const auto MARKDOWN_EXT = ghc::filesystem::path(".markdown");
static const auto SH_EXT = ghc::filesystem::path(".sh");
static const auto DIFF_MATCHERS = lnav::pcre2pp::code::from_const(
R"(^--- .*\n\+\+\+ .*\n)", PCRE2_MULTILINE);
@ -129,6 +130,9 @@ detect_text_format(string_fragment sf,
")",
PCRE2_MULTILINE | PCRE2_CASELESS);
static const auto SH_MATCHERS
= lnav::pcre2pp::code::from_const("^#!.+sh\\b", PCRE2_MULTILINE);
if (path) {
while (FILTER_EXTS.count(path->extension()) > 0) {
path = path->stem();
@ -171,6 +175,10 @@ detect_text_format(string_fragment sf,
if (stem == MAKEFILE_STEM) {
return text_format_t::TF_MAKEFILE;
}
if (stem == SH_EXT) {
return text_format_t::TF_SHELL_SCRIPT;
}
}
{
@ -186,6 +194,10 @@ detect_text_format(string_fragment sf,
return text_format_t::TF_DIFF;
}
if (SH_MATCHERS.find_in(sf).ignore_error()) {
return text_format_t::TF_SHELL_SCRIPT;
}
if (MAN_MATCHERS.find_in(sf).ignore_error()) {
return text_format_t::TF_MAN;
}

@ -57,6 +57,7 @@ enum class text_format_t {
TF_YAML,
TF_TOML,
TF_DIFF,
TF_SHELL_SCRIPT,
};
namespace fmt {
@ -115,6 +116,9 @@ struct formatter<text_format_t> : formatter<string_view> {
case text_format_t::TF_DIFF:
name = "text/x-diff";
break;
case text_format_t::TF_SHELL_SCRIPT:
name = "text/x-shellscript";
break;
}
return formatter<string_view>::format(name, ctx);
}

@ -455,6 +455,11 @@ setup_highlights(highlight_map_t& hm)
")"))
.with_nestable(false)
.with_role(role_t::VCR_VARIABLE);
hm[{highlight_source_t::INTERNAL, "yaml.var"}]
= highlighter(xpcre_compile("^\\s*(?:- )?[a-zA-Z_\\-]+:(?:\\s+|$)"))
.with_nestable(false)
.with_text_format(text_format_t::TF_YAML)
.with_role(role_t::VCR_VARIABLE);
hm[{highlight_source_t::INTERNAL, "rust.sym"}]
= highlighter(xpcre_compile("\\b[A-Z_][A-Z0-9_]+\\b"))
.with_nestable(false)
@ -479,11 +484,57 @@ setup_highlights(highlight_map_t& hm)
.with_text_format(text_format_t::TF_C_LIKE)
.with_text_format(text_format_t::TF_JAVA)
.with_role(role_t::VCR_KEYWORD);
hm[{highlight_source_t::INTERNAL, "shell"}]
= highlighter(xpcre_compile("(?:"
"\\bbreak\\b|"
"\\bcase\\b|"
"\\bcd\\b|"
"\\bcontinue\\b|"
"\\bdeclare\\b|"
"\\bdefault\\b|"
"\\bdo\\b|"
"\\bdone\\b|"
"\\becho\\b|"
"\\belif\\b|"
"\\belse\\b|"
"\\besac\\b|"
"\\beval\\b|"
"\\bexit\\b|"
"\\bexport\\b|"
"\\bfalse\\b|"
"\\bfi\\b|"
"\\bfor\\b|"
"\\bfunction\\b|"
"\\bif\\b|"
"\\bin\\b|"
"\\blocal\\b|"
"\\bprintf\\b|"
"\\bpwd\\b|"
"\\bread\\b|"
"\\breadonly\\b|"
"\\breturn\\b|"
"\\bset\\b|"
"\\bshift\\b|"
"\\bsource\\b|"
"\\btest\\b|"
"\\bthen\\b|"
"\\btrap\\b|"
"\\btrue\\b|"
"\\bunset\\b|"
"\\bunsetenv\\b|"
"\\buntil\\b|"
"\\bwhich\\b|"
"\\bwhile\\b"
")"))
.with_nestable(false)
.with_text_format(text_format_t::TF_SHELL_SCRIPT)
.with_role(role_t::VCR_KEYWORD);
hm[{highlight_source_t::INTERNAL, "num"}]
= highlighter(xpcre_compile(R"(\b-?(?:\d+|0x[a-zA-Z0-9]+)\b)"))
.with_nestable(false)
.with_text_format(text_format_t::TF_C_LIKE)
.with_text_format(text_format_t::TF_JAVA)
.with_text_format(text_format_t::TF_YAML)
.with_role(role_t::VCR_NUMBER);
hm[{highlight_source_t::INTERNAL, "fun"}]
= highlighter(xpcre_compile(R"((\w+)\()"))

@ -1194,6 +1194,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_sql_xml_func.sh_fefeb387ae14d4171225ea06cbbff3ec43990cf0.out \
$(srcdir)/%reldir%/test_sql_yaml_func.sh_dc189d02e8979b7ed245d5d750f68b9965984699.err \
$(srcdir)/%reldir%/test_sql_yaml_func.sh_dc189d02e8979b7ed245d5d750f68b9965984699.out \
$(srcdir)/%reldir%/test_text_file.sh_0bba304f34ae07c4fa9e91e0b42f5fe98654a6a8.err \
$(srcdir)/%reldir%/test_text_file.sh_0bba304f34ae07c4fa9e91e0b42f5fe98654a6a8.out \
$(srcdir)/%reldir%/test_text_file.sh_1ce4056d72b871f8bb844c86aade2a9b1da58030.err \
$(srcdir)/%reldir%/test_text_file.sh_1ce4056d72b871f8bb844c86aade2a9b1da58030.out \
$(srcdir)/%reldir%/test_text_file.sh_4226123565a53b4e3f80e602c1f294721e8e07bf.err \

@ -0,0 +1,26 @@
#! /bin/sh
if test x"${AUTORECONF}" = x""; then
autoreconf -V 1>/dev/null 2>/dev/null
if test $? -eq 0; then
AUTORECONF=autoreconf
fi
fi
if test x"${AUTORECONF}" != x""; then
${AUTORECONF} -vfi -I m4
else
AUTOCONF=${AUTOCONF:-autoconf}
AUTOMAKE=${AUTOMAKE:-automake}
AUTOHEADER=${AUTOHEADER:-autoheader}
ACLOCAL=${ACLOCAL:-aclocal}
${AUTOCONF} --version
${AUTOMAKE} --version
${ACLOCAL} -I m4 -I .
${AUTOHEADER} -I .
${AUTOMAKE} --add-missing --copy --force-missing --foreign
${AUTOCONF}
fi

@ -66,3 +66,6 @@ run_cap_test ${lnav_test} -n \
-c ";SELECT top_meta FROM lnav_views WHERE name = 'text'" \
-c ':write-json-to -' \
< ${test_dir}/example.patch
run_cap_test ${lnav_test} -n \
< ${top_srcdir}/autogen.sh

Loading…
Cancel
Save