I worked around this problem using a shell script that auto-reloads less
on exit:
while true; do less -K file.txt || exit; done
With this script, I can hit q
to reload the file, and CTRL+C
to exit back to the bash shell. The CTRL+C
behavior is enabled via the -K
option. Your last search term will be preserved.
This can be further refactored by using the colon (:
) to create an empty expression, via do :
...
while less -K file.txt; do : ; done
Drawbacks
The current viewing position will always be rest to line 0.
Practical Example using mintty
In my windows (GitBash) environment I set up a script that opens a new terminal window (mintty) for less-viewing a file:
lesswin() { mintty bash -c "while less -K \"$@\"; do : ; done;" & }
tail -f foo.log | grep bar
, and to be able to dynamically change the grep command with restarting the tail/grep pipeline.