tail -f /var/log/foo.log | fzf +s
Or something similar for output from a dev server: make serve | fzf --ansi +s tail -f /var/log/foo.log | fzf +s
Or something similar for output from a dev server: make serve | fzf --ansi +s less +F -p pattern /path/to/log
(Ctrl-C to break out of tail mode. /pattern to interactively set search pattern.)I use this all the time, especially when I'm on a machine that I don't want to bother installing something like fzf on.
&pattern
Display only lines which match the pattern; lines which do not
match the pattern are not displayed. If pattern is empty (if
you type & immediately followed by ENTER), any filtering is
turned off, and all lines are displayed. While filtering is in
effect, an ampersand is displayed at the beginning of the
prompt, as a reminder that some lines in the file may be
hidden. Multiple & commands may be entered, in which case only
lines which match all of the patterns will be displayed.
Indeed, I thought it would behave like you describe.. when I was refreshing my memory of how the negative pattern filtering worked, I first did &/pattern and then &/^Npattern, and was surprised to see that it displayed zero matching lines.this is my version of less:
% less --version
less 581.2 (POSIX regular expressions)
Copyright (C) 1984-2021 Mark Nudelman[1]: https://github.com/gwsw/less/commit/6a070fc53799fb86e0fe3880...
As for integrating with a “genders” host DB, there’s no direct support for it. But, lnav is scriptable, so I’m pretty sure it’s possible to write a script that does what you want. I can help with that if post in the github discussion: https://github.com/tstack/lnav/discussions
Edit: Ah, I see. According to another comment you see the output of the file as it changes.
fzf will receive that input and in this case accumulate the new lines that have come in from tail -f. It will then stay around, present an interactive full screen text ui, and let you interactively filter the set of received lines based on substrings you enter at the fzf prompt. This while continuously incorporating new log lines coming from the pipe, from tail -f. The +s just says not to sort the lines, keeping the matches in the same order they appeared in the logs.
- automatically have this for any command that outputs more than 10 lines?
- automatically exit when the main command (for example a dev server) exits?
- print the output of the main command to stdout after this is done?
https://gist.github.com/jpouellet/5278239
Mine blinks a little light if a command finishes after 30 seconds, and sends me an email if something takes over a minute.
Probably not. The output of a command typically goes directly to the terminal and does not pass through the shell, so the shell has no idea how many lines there are.
You could write a shell where that's not the case, but that would have issues with interactive things - what happens if you run e.g. vim or htop in that context?
You can pipe to `less -F` (`--quit-if-one-screen`), but note that the version of `less` shipped with macOS has a bug and might just swallow the output instead.
``` -F ........ --quit-if-one-screen Quit if entire file fits on first screen. ```
git branch | fzf | xargs git checkout
_ ._ _ , _ ._
(_ ' ( ` )_ .__)
( ( ( ) `) ) _)
(__ (_ (_ . _) _) ,__)
`~~`\ ' . /`~~`
; ;
/ \
_____________/_ __ \_____________ [alias]
fza = "!git ls-files -m -o --exclude-standard | fzf -m --print0 | xargs -0 git add"
Then if you run "git fza" you'll get a list of changed files in your repo, which you can use TAB to select/deselect. Hit enter and the selected files will be staged, ready for a commit. Extra cool is that it works from any subdirectory of your repo because it always lists files from the root of the repository. It's really useful for selectively adding lots of files from the command line.I then alias "ga" to "git fza" for even less typing :)
#.zshrc
alias -g F=" | fzf --multi"