fd icon indicating copy to clipboard operation
fd copied to clipboard

Suggestion: optional index numbering for search results?

Open peterkos opened this issue 2 years ago • 4 comments

This may be out of scope of fd, but I think it'd be cool to have an indexed results list. I'm imagining a workflow like this, with -I for -Index:

> fd -I main.rs ~/Code/GitHub
[0]  /Users/peterkos/Code/GitHub/dura/src/main.rs
[1]  /Users/peterkos/Code/GitHub/rolex/src/main.rs
[2]  /Users/peterkos/Code/GitHub/rusty-chess-engine/src/main.rs
[3]  /Users/peterkos/Code/GitHub/SwiftToPlantUMLConverter/main.rs
[4]  /Users/peterkos/Code/GitHub/calcdnd/src/main.rs
[5]  /Users/peterkos/Code/GitHub/ta-mixer-bots/team-reset-bot/src/main.rs
[6]  /Users/peterkos/Code/GitHub/clef/src/main.rs
[7]  /Users/peterkos/Code/GitHub/alda-rust-lib/src/main.rs
[8]  /Users/peterkos/Code/GitHub/rusty-chess/src/main.rs
[9]  /Users/peterkos/Code/GitHub/depshow/src/main.rs
[10] /Users/peterkos/Code/GitHub/zola/src/main.rs
> fd cd 10
> pwd
/Users/peterkos/Code/GitHub/zola/src/main.rs

This way you can easily jump to a result w/o having to select a specific directory or file.

peterkos avatar May 20 '22 20:05 peterkos

Would piping the fd output to nl work?

fd -I main.rs ~/Code/GitHub | nl

or

fd -l main.r ~/Code/GitHub | nl |  awk '{ $1 = "[" $1 "]"; print}'

if you want the square brackets.

tmccombs avatar May 20 '22 22:05 tmccombs

Yes for numbering, but then to use that as a shortcut for a cd afterwards; something like "Jump to result 5" and it auto-copies the path in, if that makes sense

peterkos avatar May 21 '22 00:05 peterkos

Ah I see. You can do something like:

fd -l main.r ~/Code/GitHub | nl | awk '{$1 = "[" $1 "]"; print}' | fzf | sed -E 's/^\[[0-9]+\] //'

using fzf or skim

tmccombs avatar May 22 '22 05:05 tmccombs

I also recommend looking into fzf.

sharkdp avatar May 22 '22 07:05 sharkdp