Select file uniquely based on contents #3898
-
Hi, I am trying to make a notes selector. I have a directory where each file is a note. I want to be able to select multiple ones that match a search query (fuzzy) and output them. The catch is that I want the selecting to be unique for the file. For example, suppose I search query A and then select a file from the results. Then, I search query B which matches the same file at a different line number. This file should already be selected at this point since I selected it with query A. Here is my attempt so far: INITIAL_QUERY="${*:-}"
fzf --multi --ansi --query "$INITIAL_QUERY" \
--bind "start:reload:$RG_PREFIX {q}" \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--prompt 'notes-selector:fzf> ' \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' |
awk -F: '!seen[$1]++ {printf "%s ", $1}' | sed 's/ $//' The I guess the ideal workflow would be that fzf only shows me the filename (not the line containing the match), but the preview window shows the line containing the match. Then it should be much easier to get Any help would be appreciated. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Beta Was this translation helpful? Give feedback.
An action as you described, to select all entries in the list where the first field is the same as in the currently selected line, is not an action currently present.
Alternatively, you could try to modify your function, and on every ⇥ Tab press, the preview is altered to show your current selection. Upon triggering the
focus
event (a vertical cursor movement or a search result update), the preview switches back. When you hit ⏎ Enter, a unique list…