Feature request: ctrl-t start with current word in search
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.58.0 (65db735)
OS
- [x] Linux
- [ ] macOS
- [ ] Windows
- [ ] Etc.
Shell
- [x] bash
- [ ] zsh
- [ ] fish
Problem / Steps to reproduce
This is a new request for an existing closed issue: #3195 "Option for Ctrl-T to use current command-line content as a search pattern"
I believe I have a usecase that wasn't discussed in the previous issue where invoking ctrl-T and using the current WORD as a starting point would be useful: Opening png files with firefox.
The issue is that firefox tries to be helpful and among the completions doesn't include files it thinks you don't want to open. Example:
mkdir pictures
touch pictures/potato.png
firefox pictures/<TAB>
Result: potato.png does not get completed.
My FZF configuration:
source "$XDG_CONFIG_HOME/fzf/key-bindings.bash"
source "$XDG_CONFIG_HOME/bash/fzf-bash-completion.sh"
bind -x '"\t": fzf_bash_completion'
Firefox does support opening png:s so this is arguably an issue with firefox, but it would be nice to circumvent it by invoking ctrl-t as described here.
Questions: Are there situations when one would prefer that [a-z/] followed by <TAB> doesn't include the current word in the search pattern?
Have you tried using fuzzy completion? i.e. firefox pictures/**<TAB>
My FZF configuration:
source "$XDG_CONFIG_HOME/fzf/key-bindings.bash" source "$XDG_CONFIG_HOME/bash/fzf-bash-completion.sh" bind -x '"\t": fzf_bash_completion'
This is quite different from our current recommendation.
- https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration
Could you share how you ended up with it?
I probably invented source "$XDG_CONFIG_HOME/fzf/key-bindings.bash by myself, can't remember. The other two lines of config are from: https://github.com/lincheney/fzf-tab-completion
I removed that and tried with eval "$(fzf --bash)" as per the instructions now, and ** on it's own works, but firefox ** does not show anything. (Is firefox hijacking the completion mechanism before fzf get's to do anything?)
In a folder with this content:
.
├── a.html
├── b.png
├── c.svg
├── d.xml
└── subdir
-
ls<TAB>lists all 5 -
ls **<TAB>also lists all 5 -
firefox <TAB>listsa.htmlandsubdir -
firefox **<TAB>lists none
Does complete | grep firefox show anything?
Yes, it shows a function:
$ complete | fzf
complete -F _firefox firefox
$ declare -f _firefox
_firefox ()
{
local cur prev words cword split;
_init_completion -s || return;
[[ $cur == -MOZ_LOG*=* ]] && prev=${cur%%=*} cur=${cur#*=};
case $prev in
--help | --version | --display | --UILocale | -MOZ_LOG | --new-window | --new-tab | --private-window | --window-size | --search | --start-debug
return
;;
--profile | --screenshot)
_filedir -d;
return
;;
-MOZ_LOG_FILE)
_filedir log;
return
;;
--recording-file)
_filedir;
return
;;
--debugger | -d)
COMPREPLY=($(compgen -c -- "$cur"));
return
;;
esac;
$split && return;
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"));
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace;
return;
fi;
_filedir "@(?([xs])htm?(l)|pdf|txt)"
}
That explains. In bash, fuzzy completion only works for a predefined set of commands and commands with no completion defined. Because firefox has its own completion in your environment, fuzzy completion is not triggered. To enable fuzzy completion for firefox, follow the instruction in https://github.com/junegunn/fzf?tab=readme-ov-file#supported-commands.