fzf-tab-completion

Tab completion using fzf
授权协议 GPL-3.0 License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 田丰
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

fzf-tab-completion

Tab completion using fzf in zsh, bash, GNU readline apps (e.g. python, php -a etc.)

This is distinct fromfzf's own implementation for completion,in that it works with the existing completion mechanismsrather than creating a new mechanism.

Example

Click here to show screencast

Installation

  1. You need to install fzf first.

  2. Clone this repository: git clone https://github.com/lincheney/fzf-tab-completion ...

    • you can also choose to download only the scripts you need, up to you.
  3. Follow instructions on how to set up for:

  4. The following environment variables are supported, just as in fzf's "vanilla" completion.

    • $FZF_TMUX_HEIGHT
    • $FZF_COMPLETION_OPTS
    • $FZF_DEFAULT_OPTS

    See also https://github.com/junegunn/fzf#settings

    Avoid changing these fzf flags: -n, --nth, --with-nth, -d

zsh

Add to your ~/.zshrc:

source /path/to/fzf-tab-completion/zsh/fzf-zsh-completion.sh
bindkey '^I' fzf_completion

If you have also enabled fzf's zsh completion, then the bindkey line is optional.

Note that this does not provide **-style triggers,you will need to enable fzf's zsh completion as well.

tmux

$FZF_TMUX_OPTS is respected same as in fzfhowever you must have fzf's keybindings enabled as well.

Searching display strings

By default, display strings are shown but cannot be searched in fzf.This is configurable via zstyle:

# only for git
zstyle ':completion:*:*:git:*' fzf-search-display true
# or for everything
zstyle ':completion:*' fzf-search-display true

Specifying custom fzf options

You can specify custom fzf options with the fzf-completion-opts style.This allows you to have different options based on the command being completed(as opposed to the $FZF_DEFAULT_OPTS etc environment variables which are global).

This is most useful for changing the --preview option.Use {1} for the selected text (or {+1} if using multi-select).Note {1} or {+1} will come through "shell-escaped", so you will need to unescape it, e.g. using eval or printf %b

# basic file preview for ls (you can replace with something more sophisticated than head)
zstyle ':completion::*����:*' fzf-completion-opts --preview='eval head {1}'

# preview when completing env vars (note: only works for exported variables)
# eval twice, first to unescape the string, second to expand the $variable
zstyle ':completion::*:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' fzf-completion-opts --preview='eval eval echo {1}'

# preview a `git status` when completing git add
zstyle ':completion::*:git::git,add,*' fzf-completion-opts --preview='git -c color.status=always status --short'

# if other subcommand to git is given, show a git diff or git log
zstyle ':completion::*:git::*,[a-z]*' fzf-completion-opts --preview='
eval set -- {+1}
for arg in "$@"; do
    { git diff --color=always -- "$arg" | git log --color=always "$arg" } 2>/dev/null
done'

bash

Add to your ~/.bashrc:

source /path/to/fzf-tab-completion/bash/fzf-bash-completion.sh
bind -x '"\t": fzf_bash_completion'

If you are using a bash that is dynamically linked against readline (LD_PRELOAD= ldd $(which bash))you may prefer (or not!) to use the readline method instead.

tmux

$FZF_TMUX_OPTS is respected same as in fzfhowever you must have fzf's keybindings enabled as well.

Custom loading message

bash clears the prompt and input line before running the completion,so a loading message is printed instead.

You can customise the message by overriding the _fzf_bash_completion_loading_msg() function.

For example the following "re-prints" the prompt and input lineto make this less jarring(note this may or may not work, there's no detection of $PS2 and there is always some unavoidable flicker):

_fzf_bash_completion_loading_msg() { echo "${PS1@P}${READLINE_LINE}" | tail -n1; }

readline

NOTE: This uses a LD_PRELOAD hack, is only supported on Linux and only for GNU readline(not e.g. libedit or other readline alternatives).

  1. Run: cd /path/to/fzf-tab-completion/readline/ && cargo build --release
  2. Copy/symlink /path/to/fzf-tab-completion/readline/bin/rl_custom_complete into your $PATH
  3. Add to your ~/.inputrc:
    $include function rl_custom_complete /path/to/fzf-tab-completion/readline/target/release/librl_custom_complete.so
    "\t": rl_custom_complete
    
  4. Build https://github.com/lincheney/rl_custom_function/
    • this should produce a file librl_custom_function.so which you will use with LD_PRELOAD in the next step.
  5. Run something interactive that uses readline, e.g. python:
    LD_PRELOAD=/path/to/librl_custom_function.so python
  6. To apply this all applications more permanently,you will need to set LD_PRELOAD somewhere like /etc/environment or ~/.pam_environment.
    • NOTE: if you set LD_PRELOAD in your .bashrc, or similar, it will affect applications run from bashbut not the parent bash process itself.
    • See also: link

These are the applications that I have seen working:

  • python2, python3
  • php -a
  • R
  • lftp
  • irb --legacy (the new irb in ruby 2.7 uses ruby-reline instead of readline)
  • gdb
  • sqlite3
  • bash (only when not statically but dynamically linked to libreadline)

Related projects

  •   今天无意中尝试了fzf,才发现这个工具的威力无穷,毕竟是非常好的工具,第一次都把它的优点都释放出来也不现实,先熟悉一下吧,后面在实战中再不断地学习总结。 它是什么:   Fuzzy finder 是一款使用 GO 语言编写的交互式的 Unix 命令行工具。可以用来查找任何 列表 内容,文件、Git 分支、进程等。所有的命令行工具可以生成列表输出的都可以再通过管道 pipe 到 fzf 上进行搜

 相关资料
  • fzf

    fzf 是一个通用的命令行模糊查找器,它是一个用于命令行的交互式 Unix 过滤器,可以用于定位多种资源,包括文件、命令历史、进程、主机名、书签与 git commit 等。 特性包括: 便携无依赖性 非常快 最全面的功能集 布局灵活 可组合 Vim/Neovim 插件,提供键绑定和模糊自动完成

  • fzf-scripts This is a collection of scripts I've written that use fzf Almost all of them require various tools from coreutils like awk sed cut, and probably make use of GNU extensions. fv Lists or sea

  • Kubectl-fzf kubectl-fzf provides a fast and powerful fzf autocompletion for kubectl. Table of Contents Kubectl-fzf Table of Contents Features Requirements Installation Cache builder Local installation

  • kube-fzf Shell commands using kubectl and fzf for command-line fuzzy searching of Kubernetes Pods. It helps to interactively: search for a Pod tail a container of a Pod exec in to a container of a Pod

  • 选项卡在Bootstrap Navigation Elements一章中介绍。 通过组合一些数据属性,您可以轻松创建选项卡式界面。 使用此插件,您可以通过选项卡或药丸转换本地内容的窗格,甚至可以通过下拉菜单进行转换。 如果您想单独包含此插件功能,那么您将需要tab.js 另外,如Bootstrap插件概述一章所述,您可以包含bootstrap.js或缩小的bootstrap.min.js 。 用法

  • Tab

    Extends Composite A container representing a single tab of a TabFolder widget. Import this type with “const {Tab} = require('tabris');” Properties badge iOS Type: string A badge to attach to the tab.