Kind of like an interactive
tree --fromfilecommand
An interactive tree-based search tool with file preview. Give it some path-looking things, and it'll make them readable
go install github.com/sftsrv/tri@latest# files in a directory
find ./ | tri
# use alternate preview
find ./ | tri --preview glow
# files in a pr
git diff --name-only | tri
Use Regexps to parse the input string to create more complex commands
Escaping of regex special chars will depend on your shell
# viewing a formatted git log and showing the changes for each hash
git log --pretty=format:"%h %f"
| tri --preview "git show $1" --pattern "^(\w+)"
# using a more complex regexp and command
git log --pretty=format:"%h %f"
| tri --preview "echo title: $title hash: $hash" --pattern "(?<hash>\w+) (?<title>.*)"
The structure of the regexp provided should be compatible with Go's implementation, with the following affordances made:
- Named capture groups can be specified as
<name>instead of?P<name> - Regexps are always matched against a single line - so multiline captures are not meaningful
References in pattern are indicated with a $ in the pattern
- `$` refers to the entire match
- `$0` (entire match), `$1` (first capture group), etc. refer to capture groups in order of capture
- `$name` refers to named capture groups
There are a lot of smaller improvements still left, but I've been using it for some time now and seems to work fine for me - but if you're keen to pick something up then do feel free to
- Search
- Preview with syntax highlighting (using bat if available)
- Custom preview command
- File selection
- Expand/Collapse folders
- Flatten direct paths (using
--flatflag) - Print tree (using
--printflag) - Async/non-blocking previews
- Make splits adjustable via keybinding (resize width of file tree)
- Allow explicit placeholder for file name in output command (like how it works for)
- Uses Regexp for pattern definition and dynamic commands
- Move user search input to separate thread
- Make flat mode reactive to searching
- Make it possible to toggle flat on and off
- Tests for different formats and structures
- Fix fuzzy searching
- Regex based search in editor and via flag?
- Multi file select?
- Use
Viewport(https://github.com/charmbracelet/bubbles) withreflow(https://github.com/muesli/reflow) for improved wrapping? - better is being able to provide the size of the active terminal to the underlying process but I have no idea how to do that
