8

I recently ran into fzf, which seems like a fantastic little tool, but there's one thing I'm having trouble with: given input with multiple fields per line, how do I configure it to return only a particular field when pressing enter? The accept action, which is the default binding for the enter key, doesn't accept any parameters...you can't use --bind enter:accept(1) or something like that.

The --nth and --with-nth options affect which fields are searched (--nth) or displayed (--with-nth), but don't impact what gets returned.

For example, if I run a command like:

ps -fe | fzf --some-options...

I'd like pressing enter on a line that looks like this:

  root        2067       1  0 08:41 ?        00:00:00 /usr/sbin/gdm

To emit only 2067 on stdout.

Is the only option to post-process the output from fzf with another tool (e.g., awk)?

larsks
  • 4,212

2 Answers2

11
ps -fe | fzf --bind 'enter:execute(echo {2})+abort'

That gives you the second field

or for multiselection:

ps -fe | fzf -m --bind 'enter:execute(echo {+2})+abort'
testoflow
  • 137
4

The answer by testoflow gave me a very good hint, and I got to find out a solution using become().

ps -fe | fzf --bind 'enter:become(echo {2})'
ps -fe | fzf -m --bind 'enter:become(echo {+2})'