simont |
Fri 2002-11-08 10:48 |
I use "less" in -M mode (long prompt including filename, line number and percentage of file). This is fine most of the time, but when less is reading from stdin it doesn't display a filename in the prompt at all. If less's stdin is coming from some script I've written, I'd often quite like to configure what less displays in place of the filename, instead of having it fixed to a blank string. If my script has just (for example) pulled a bug report out of the database at work and formatted it for display using less, I'd quite like the filename field in the less prompt to display the bug number, so I can remember what I'm doing. I've just worked out a moderately cunning way of doing that: open LESS, "|env LESSOPEN='|cat' less $filename";
Because $LESSOPEN is normally required to contain a "%s" which is replaced by the filename; so defining it without one causes the filename to bear no relation to the means used to acquire the data. Hence, I can supply a "filename" on the command line, which less will obediently display in its prompt but which will not affect the source of the data it actually displays. I'm quite pleased with that. :-) |
|