Description
I would like to write a script for lnav but due to the lack of branching / control flow allowed in lnav scripting I don't think it is possible to write the script.
What I want the script to do:
In some logs a filename is given but not the full path to the file, leaving possible ambiguity if there are multiple files with the same name. What I would like to do is when the script is called on a log line with an unambiguous file I'd like to run :open on that file
, if however the filename is ambiguous I'd like create an sql table view in front of them of all the unambiguous options and then if they run the script with their cursor on one of the sql result lines I'd like to open the file associated with that line.
The problem I'm having (though I could just be limited by not understanding how best to use the lnav scripting language), is that since sometimes I want the last line of the script to be a select clause to display the sql results, I don't think I have any way to conditionally have that happen. I think SQL gives me the ability to SELECT IF or something along those lines maybe, but the problem is that I don't know how to avoid calling :open
in the ambiguous cases.
My proposed idea is to have a command :return-if <condition>
. I think this is the minimal amount of conditional logic that could be added to lnav without needing to extend lnav script to handle if...else
statements that might get cumbersome and tedious. This would just allow the bare minimum amount of conditional, which technically could allow for any arbitrary if-else statement without actually adding that to the language.
return-if false/0
should always noop
return-if true/1
should exit the lnav script if called by lnav
return-if true/1
should return control from the inner script to the outer script if called within an inner script
Let me know if this makes sense or if I can already achieve what I want from this script without this command. TY!
Activity