fzf:如何返回“ID”/行号?

fzf:如何返回“ID”/行号?

我有一组想要运行的行(项目+描述)fzf -m。例如:

item1: Some description
item1: Another description
item2: Yet another description

选择后,我希望 fzf 返回行号(例如1 3)而不是行本身,因为: 1)我不想包含说明; 2)项目不是唯一的。

确实,我可以先在行前加上行号:

1: item1: Some description
2: item1: Another description
3: item2: Yet another description

然后稍后将其提取。但我认为如果能指示 fzf 这样做就太好了。它将使一些事情变得更容易,并为该工具带来更多可能性。

答案1

fzf已经可以通过--with-nth将显示的(和搜索的)行更改为仅原始行的某些字段来执行此操作。所以我们从以下开始:

1: item1: Some description
2: item1: Another description
3: item2: Yet another description

然后使用:

fzf -d: --with-nth 2..

这意味着跳过显示第一个字段(字段之间用冒号分隔)。 fzf 将返回如下内容:

1: item1: Some description
3: item2: Yet another description

您可以从中提取行号。

相关内容