Page
Library
Module
Module type
Parameter
Class
Class type
Source
TUI multiline fuzzy document finder
Think interactive grep for text files, PDFs, DOCXs, etc, but word/token based instead of regex and line based, so you can search across lines easily.
Docfd aims to provide good UX via integration with common text editors and PDF viewers, so you can jump directly to a search result with a single key press.
Navigating repo:
Quick search with non-interactive mode:
Navigating PDF and opening it to the closest location to the selected search result via PDF viewer integration:
Docfd uses the text editor specified by $VISUAL
(this is checked first) or $EDITOR
.
Docfd opens the file at first line of search result for the following editors:
nano
nvim
/vim
/vi
kak
hx
emacs
micro
jed
/xjed
Docfd guesses the default PDF viewer based on the output of xdg-mime query default application/pdf
, and invokes the viewer either directly or via flatpak depending on where the desktop file can be first found in the list of directories specified by $XDG_DATA_DIRS
.
Docfd opens the file at first page of the search result and starts a text search of the most unique word of the matched phrase within the same page for the following viewers:
Docfd opens the file at first page of the search result for the following viewers:
Statically linked binaries are available via GitHub releases.
Docfd is also packaged on:
docfd-bin
) by kseistrupdocfd
) by chewblackaNotes for packagers: Outside of the OCaml toolchain for building (if you are packaging from source), Docfd also requires the following external tools at run time for full functionality:
pdftotext
from poppler-utils
for PDF supportpandoc
for support of .epub
, .odt
, .docx
, .fb2
, .ipynb
, .html
, and .htm
filesfzf
for file selection menucommand | docfd
Docfd uses single file view when source of document is piped stdin.
No paths should be supplied as arguments in this case. If any paths are specified, then stdin is ignored.
docfd [PATH]...
The list of paths can contain directories. Each directory in the list is scanned recursively for files with one of the following extensions by default:
.txt
.md
.pdf
You can change the file extensions to use via --exts
, or add onto the list of extensions via --add-exts
.
If the list PATH
s is empty, then Docfd defaults to scanning the current directory .
.
If any of the file ends with .pdf
, then pdftotext
is required to continue.
If exactly one file is specified in the list of paths, then Docfd uses single file view. Otherwise, Docfd uses multi-file view.
docfd [PATH]... ?
The ?
can be in any position in the path list. If any of the path is ?
, then file selection of the discovered files via fzf
is invoked.
docfd [PATH]... --paths-from paths.txt
The final list of paths used is then the concatenation of PATH
s and paths listed in paths.txt
, which has one path per line.
The list PATH
s does not default to .
when --paths-from
is used.
The search field takes a search expression as input. A search expression is one of:
fuzzy search
?expression
(optional)(expression)
expression | expression
(or), e.g. go ( left | right )
To use literal ?
, (
, )
or |
, a backslash (\
) needs to be placed in front of the character.
For a phrase with optional operator, such as ?word0 word1 ...
, the first word is grouped implicitly, i.e. it is treated as ?(word0) word1 ...
.
Document content and user input in the search field are tokenized/segmented in the same way, based on:
A search phrase is a list of said tokens.
Search procedure is a DFS through the document index, where the search range for a word is fixed to a configured range surrounding the previous word (when applicable).
A token in the index matches a token in the search phrase if they fall into one of the following cases:
Search results are then ranked using heuristics.
Navigation mode
Switch to search mode
/
Clear search phrase
x
Exit Docfd
Esc
, Ctrl+C
or Ctrl+Q
Print selected search result to stderr
p
Print path of selected document to stderr
Shift
+P
Search mode
Enter
to confirm search phrase and exit search modeThe default TUI is divided into four sections:
Bottom pane consists of:
Docfd operates in modes, the initial mode is navigation mode.
Navigation mode
Scroll down the document list
j
Scroll up the document list
k
Scroll down the search result list
Shift
+J
Shift
+Down arrowShift
+Page downScroll up the document list
Shift
+K
Shift
+Up arrowShift
+Page upOpen document
Enter
$VISUAL
first, if that fails then Docfd tries $EDITOR
Switch to single file view
Tab
If the specified path to Docfd is not a directory, then single file view is used.
In this view, the TUI is divided into only two sections:
The controls are simplified in single file view, namely Shift
is optional for scrolling through search result list.
Navigation mode
Scroll down the search result list
j
Shift
+J
Shift
+Down arrowShift
+Page downScroll up the document list
k
Shift
+K
Shift
+Up arrowShift
+Page upOpen document
Enter
$VISUAL
first, if that fails then Docfd tries $EDITOR
Switch to multi-file view
Tab
File auto-reloading is not supported for PDF files, as PDF viewers are invoked in the background via shell. It is possible to support this properly in the ways listed below, but requires a lot of engineering for potentially very little gain:
inotify
or via checking file modification times periodically.