[cmds] add more env vars to :pipe-line-to

Related to #1224
pull/1235/head
Tim Stack 5 months ago
parent 53d5e408fa
commit 96e6950884

@ -824,6 +824,8 @@ execute_init_commands(
wait_for_children();
lnav_data.ld_view_stack.top() |
[&ec](auto* tc) { ec.ec_top_line = tc->get_selection(); };
log_debug("init cmd: %s", cmd.c_str());
{
auto _sg

@ -954,7 +954,7 @@
:pipe-line-to *shell-cmd*
^^^^^^^^^^^^^^^^^^^^^^^^^
Pipe the top line to the given shell command
Pipe the focused line to the given shell command. Any fields defined by the format will be set as environment variables.
**Parameters**
* **shell-cmd\*** --- The shell command-line to execute

@ -296,7 +296,8 @@ public:
std::vector<attr_line_t> top_line{1};
this->lv_source->listview_value_for_rows(*this, this->lv_top, top_line);
this->lv_source->listview_value_for_rows(
*this, this->get_selection(), top_line);
return func(top_line[0]);
}

@ -1882,7 +1882,7 @@ com_pipe_to(exec_context& ec,
path_v.emplace_back(lnav::paths::dotlnav() / "formats/default");
if (pipe_line_to && tc == &lnav_data.ld_views[LNV_LOG]) {
logfile_sub_source& lss = lnav_data.ld_log_source;
auto& lss = lnav_data.ld_log_source;
log_data_helper ldh(lss);
char tmp_str[64];
@ -1898,6 +1898,17 @@ com_pipe_to(exec_context& ec,
tmp_str, sizeof(tmp_str), ldh.ldh_line->get_timeval());
setenv("log_time", tmp_str, 1);
setenv("log_path", ldh.ldh_file->get_filename().c_str(), 1);
setenv("log_level", ldh.ldh_line->get_level_name(), 1);
if (ldh.ldh_line_values.lvv_opid_value) {
setenv("log_opid",
ldh.ldh_line_values.lvv_opid_value->c_str(),
1);
}
auto read_res = ldh.ldh_file->read_raw_message(ldh.ldh_line);
if (read_res.isOk()) {
auto raw_text = to_string(read_res.unwrap());
setenv("log_raw_text", raw_text.c_str(), 1);
}
for (auto& ldh_line_value : ldh.ldh_line_values.lvv_values) {
setenv(ldh_line_value.lv_meta.lvm_name.get(),
ldh_line_value.to_string().c_str(),
@ -6107,7 +6118,9 @@ readline_context::command_t STD_COMMANDS[] = {
com_pipe_to,
help_text(":pipe-line-to")
.with_summary("Pipe the top line to the given shell command")
.with_summary(
"Pipe the focused line to the given shell command. Any fields "
"defined by the format will be set as environment variables.")
.with_parameter(
help_text("shell-cmd", "The shell command-line to execute"))
.with_tags({"io"})

@ -48,7 +48,7 @@ sql_log_top_line()
if (tc.get_inner_height() == 0_vl) {
return nonstd::nullopt;
}
return (int64_t) tc.get_top();
return (int64_t) tc.get_selection();
}
static nonstd::optional<int64_t>
@ -60,7 +60,7 @@ sql_log_msg_line()
return nonstd::nullopt;
}
auto top_line = tc.get_top();
auto top_line = tc.get_selection();
auto line_pair_opt = lnav_data.ld_log_source.find_line_with_file(top_line);
if (!line_pair_opt) {
return nonstd::nullopt;
@ -85,7 +85,7 @@ sql_log_top_datetime()
}
auto top_time = lnav_data.ld_log_source.time_for_row(
lnav_data.ld_views[LNV_LOG].get_top());
lnav_data.ld_views[LNV_LOG].get_selection());
if (!top_time) {
return nonstd::nullopt;
}

@ -150,6 +150,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_cmds.sh_8d5b43c693e78804a8fb06989392fa8cccb46b7b.out \
$(srcdir)/%reldir%/test_cmds.sh_9445861db011dfa2d21a44788047de345ee291e8.err \
$(srcdir)/%reldir%/test_cmds.sh_9445861db011dfa2d21a44788047de345ee291e8.out \
$(srcdir)/%reldir%/test_cmds.sh_949826cc086c7a5c87270be172e3caa3bf8f928d.err \
$(srcdir)/%reldir%/test_cmds.sh_949826cc086c7a5c87270be172e3caa3bf8f928d.out \
$(srcdir)/%reldir%/test_cmds.sh_9527f941dc84a2ac3a030f222e41c6ccd1961cbe.err \
$(srcdir)/%reldir%/test_cmds.sh_9527f941dc84a2ac3a030f222e41c6ccd1961cbe.out \
$(srcdir)/%reldir%/test_cmds.sh_95beaabe41d72cf4c6810e79c623da759ac1c71b.err \
@ -208,8 +210,6 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_cmds.sh_ca66660c973f76a3c2a147c7f5035bcb4e8a8bbc.out \
$(srcdir)/%reldir%/test_cmds.sh_ccd326da92d1cacda63501cd1a3077381a18e8f2.err \
$(srcdir)/%reldir%/test_cmds.sh_ccd326da92d1cacda63501cd1a3077381a18e8f2.out \
$(srcdir)/%reldir%/test_cmds.sh_d0d0ff9b68adc17136329f457fe52d5addcb12c0.err \
$(srcdir)/%reldir%/test_cmds.sh_d0d0ff9b68adc17136329f457fe52d5addcb12c0.out \
$(srcdir)/%reldir%/test_cmds.sh_d1afefacbdd387f02562c8633968b0162a588502.err \
$(srcdir)/%reldir%/test_cmds.sh_d1afefacbdd387f02562c8633968b0162a588502.out \
$(srcdir)/%reldir%/test_cmds.sh_d3b69abdfb39e4bfa5828c2f9593e2b2b7ed4d5d.err \

@ -0,0 +1 @@
{"ts": "2013-09-06T22:00:49.124817Z", "lvl": "INFO", "msg": "Shutting down service", "user": "steve@example.com"} info steve@example.com

@ -1282,7 +1282,8 @@ For support questions, email:
:pipe-line-to shell-cmd
══════════════════════════════════════════════════════════════════════
Pipe the top line to the given shell command
Pipe the focused line to the given shell command. Any fields
defined by the format will be set as environment variables.
Parameter
shell-cmd The shell command-line to execute
See Also

@ -400,6 +400,12 @@ run_cap_test ${lnav_test} -n \
-c ":pipe-line-to echo \$cs_uri_stem \$sc_status" \
${test_dir}/logfile_access_log.0
run_cap_test ${lnav_test} -n \
-I ${test_dir} \
-c ":goto 5" \
-c ":pipe-line-to echo \$log_raw_text \$log_level \$user" \
${test_dir}/logfile_json.json
run_cap_test ${lnav_test} -n \
-c ":switch-to-view pretty" \
${test_dir}/textfile_json_one_line.0

Loading…
Cancel
Save