zsh: make Ctrl-T file widget “path-prefix aware” (same ^T, no new keybind)
- Dominant language
- Go
- Stars
- 83k
- Forks
- 2.9k
- Avg merge
- 17h 8m
- Merged PRs (30d)
- 10
Description
### Checklist
- [x] I have read through the manual page (`man fzf`)
- [x] I have searched through the existing issues
- [x] For bug reports, I have checked if the bug is reproducible in the latest version of fzf
### Output of `fzf --version`
0.66.1
### OS
- [ ] Linux
- [x] macOS
- [ ] Windows
- [ ] Etc.
### Shell
- [ ] bash
- [x] zsh
- [ ] fish
### Problem / Steps to reproduce
In zsh, the default Ctrl-T widget (`fzf-file-widget` from `shell/key-bindings.zsh`) always searches relative to $PWD and appends the selection(s) to the end of `$LBUFFER`.
This makes Ctrl‑T awkward when the cursor is already inside a path prefix (common workflow):
1. Type: `cat /dirB/pa`
2. Press Ctrl‑T
3. Ctrl‑T still searches from $PWD, and appends results to the end (instead of completing/replacing `pa` under `/dirB/`).
Related discussion: https://github.com/junegunn/fzf/discussions/2791
In that thread, the suggested solution is to use fuzzy completion / dedicated completion key (e.g. `/dirB/**`), which works but uses a different keybinding and a different mechanism than Ctrl‑T. I’d like Ctrl‑T
itself to handle the “path prefix is present” case.
### Proposed behavior (zsh Ctrl‑T)
When Ctrl‑T is invoked and the current token (under cursor) looks like a path prefix:
- Treat the directory part as the search root
- Seed fzf’s initial query with the basename fragment already typed
- Replace the token under cursor with the selected path(s) (rather than appending to the end of LBUFFER)
Examples:
- `cat /dirB/` should search under `/dirB`
- `cat /dirB/pa` should search under `/dirB` with initial query `pa`, and replace `pa` with the selected entry/entries
When there is no path prefix, keep current behavior unchanged.
### Implementation sketch
fish already does something similar by parsing the current token into (dir, query, prefix) and invoking fzf with `--walker-root=$dir --query=$query` (see `shell/key-bindings.fish`).
For zsh, a minimal/opt-in approach could be:
- detect the current token (ideally under cursor; at minimum, last whitespace-delimited token)
- if it contains a valid dir prefix, pass `--walker-root` + `--query` accordingly
- replace the token under cursor with selections
If changing default Ctrl‑T behavior is undesirable, this could be guarded behind an opt-in env var (default off) that switches `fzf-file-widget` into this “path-prefix aware” mode.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.