Open Shuraken007 opened 1 year ago
No, fzf
does not have that. Someone has to write a zsh completion function for it.
Completion functions for commands are stored in files with names beginning with an underscore , and these files should be placed in a directory listed in the $fpath variable. Source: HOWTO Guide zsh-users/zsh-completions
Some tools have it, for example gh
or bat
. If you have Homebrew
installed, you can see such files or checkout the zsh-users/zsh-completions github repo.
ls -1 $(brew --prefix)/share/zsh/site-functions
# _bat
# _brew
# _brew_services
# _cargo
# _delta
# _exa
# _fd
# _gh
# _git
# _hx
# _ninja
# _parallel
# _revolver
# _rg
# _yt-dlp
# _zoxide
Alternatively, you can run compdef _gnu_generic fzf
which will search the fzf
help page and list the flags found, but as the name implies, it is generic and will not work on specific options passed to flags.
# you may have to run those commands as well
autoload -Uz compinit
compinit
# run
# add the line to your '.zshrc' file if it is useful for your case
compdef _gnu_generic fzf
fzf
found on GitHub are a bit outdated or just do the same thing as compdef _gnu_generic fzf
does, but there is one version that even makes argument suggestions for certain flags
completions
directory to your $FPATH
orgit clone --depth 1 https://github.com/lmburns/dotfiles.git lmburns_zsh_completion
# .zshrc
export FPATH="$FPATH:$HOME/lmburns_zsh_completion/.config/zsh/completions"
$FPATH
cd $HOME/my_completion_folder
curl --remote-name https://raw.githubusercontent.com/lmburns/dotfiles/master/.config/zsh/completions/_fzf
# .zshrc
export FPATH="$FPATH:$HOME/my_completion_folder"
@LangLangBart - how have you founded this example? Used git search engine for files with name _fzf?
_@LangLangBart - how have you founded this example? Used git search engine for files with name fzf?
I posted the search link in my previous comment. See docs.github.com/understanding-github-code-search-syntax for more details.
# uses 'gh', 'fzf' and 'bat'
gh search code $'#compdef fzf' \
--filename '_fzf' \
--json repository,path \
--jq '.[] | [.repository.nameWithOwner, .path] | @tsv' |
fzf --delimiter '\t' --with-nth 1 \
--preview 'gh api --cache 10m repos/{1}/contents/{2} \
--jq .content | base64 --decode | bat --language zsh --number' \
--preview-window 'nohidden:right:wrap:75%' \
--bind 'ctrl-b:execute-silent:gh browse --repo {1} {2}'
@LangLangBart whoa, amazing tricks with that utils. Thanks for this cool staff.
You are on the crest of a wave, cli added code search
2 weeks ago.
https://github.com/cli/cli/releases/tag/v2.31.0
had to manually install release from github
I had to use a bit other params for bat bat --language zsh --style=numbers --color=always
wanna check your dotfiles to get some usefull tricks, but looks like they are private.
I had to use a bit other params for bat bat --language zsh --style=numbers --color=always
I missed the --color=always
, it was only set in my .zshrc
, and --number
is just an alias for --style=numbers
wanna check your dotfiles to get some usefull tricks, but looks like they are private.
Yes. I use zsh4humans as my setup. Checkout the creator's dotfiles - a true zsh
wizard.
PS: The code snippet from my previous comment was transformed into an extension - gh find-code, utilizing the newest features of fzf
.
I second that having completions would be nice. Even incomplete completions would be better than none at all. Maybe @lmburns would be willing to PR their completions?
@LangLangBart Thanks for the various tricks you shared in this thread. compdef _gnu_generic
and the github code search really useful.
https://github.com/RobSis/zsh-completion-generator is another option here for generating completions for tools which don't provide them.
Hello, greped a lot in Issues and manual, but can't find how to enable zsh completion for fzf help. I mean tab complete for fzf options like
--preview
,--multi
, e.t.c.shell/completion.bash has function _fzf_opts_completion with opts
I havn't find something like this for shell/completion.zsh probably you added some scripts to build help auto?
There are some examples bat: https://github.com/sharkdp/bat/blob/master/assets/completions/bat.zsh.in exa: https://github.com/ogham/exa/blob/master/completions/zsh/_exa ripgrep: https://github.com/BurntSushi/ripgrep/blob/master/complete/_rg