Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🐠 Configurable fzf completions for fish shell

License

NotificationsYou must be signed in to change notification settings

gazorby/fifc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fish fzf completions

CI

fifc brings fzf powers on top of fish completion engine and allows customizable completion rules

gif usage

✅ Requirements

✨ Features

  • Preview/open any file: text, image, gif, pdf, archive, binary (using external tools)
  • Preview/open command's man page
  • Preview/open function definitions
  • Preview/open full option description when completing commands
  • Recursively search for files and folders when completing paths (usingfd)
  • Preview directory content
  • Preview process trees (usingprocs)
  • Modular: easily add your own completion rules
  • Properly handle paths with spaces (needs fish 3.4+)

🚀 Install

fisher install gazorby/fifc

🔧 Usage

You only need to set one setting after install:

set-Ux fifc_editor<your-favorite-editor>

And enjoy built-in completions!

By default fifc overridetab, but you can assign another keybinding:

# Bind fzf completions to ctrl-xset-U fifc_keybinding\cx

fifc can use modern tools if available:

PreferFallback toUsed forCustom options
batcatPreview files$fifc_bat_opts
chafafilePreview images, gif, pdf etc$fifc_chafa_opts
hexylfilePreview binaries$fifc_hexyl_opts
fdfindComplete paths$fifc_fd_opts
exalsPreview directories$fifc_exa_opts
ripgreppcregrepSearch options in man pages-
procspsComplete processes and preview their tree$fifc_procs_opts
broot-Explore directory trees$fifc_broot_opts

Custom options can be added for any of the commands used by fifc using the variable mentioned in the above table.

Example:

Show line number when previewing files:

  • set -U fifc_bat_opts --style=numbers

Show hidden file by default:

  • set -U fifc_fd_opts --hidden

⚠️ Don't use quotes in variables, set them as a list:set -U fifc_exa_opts --icons --tree

🛠️ Write your own rules

Custom rules can easily be added using thefifc command. Actually, all builtin rules are added this way: seeconf.d/fifc.fish

Seefifc -h for more details.

Basically, a rule allows you to trigger some commands based on specific conditions.

A condition can be either:

  • A regex that must match commandline before the cursor position
  • An arbitrary command that must exit with a non-zero status

If conditions are met, you can bind custom commands:

  • preview: Command used for fzf preview
  • source: Command that feeds fzf input
  • open: Command binded tofifc_open_keybinding (defaults to ctrl-o)

All commands have access to the following variable describing the completion context:

VariableDescriptionCommand availability
fifc_candidateCurrently selected item in fzfall except source
fifc_commandlineCommandline part before the cursor positionall
fifc_tokenLast token from the commandlineall
fifc_groupGroup to which fish suggestions belong (possible values: directories, files, options or processes)all
fifc_extractedExtracted string from the currently selected item using theextracted regex, if anyall except source
fifc_queryfzf query. On source command, it is the initial fzf query (passed through--query option)all

fifc_group values

fifc test completion items to setfifc_group with the following conditions:

GroupCondition
directoriesAll completion items are directories
filesItems can be either filesor directories
optionsAll items match the following regex:\h+\-+\h*$
processesAll items match the following regex^[0-9]+$ (list of PID)

Matching order

By default, fifc evaluate all rules in the order in which they have been defined and stops at the first where all conditions are met.It does this each time it has to resolve source, preview and open commands.

Take the following scenario:

# Rule 1fifc-n'test "$fifc_group" = files'-p'bat$fifc_candidate'# Rule 2fifc-n'string match "*.json" "$fifc_candidate"'-p'bat -l json$fifc_candidate'

When completing path,$fifc_group will be set to "files" so the first rule will always be valid in that case, and the second one will never be reached.

Another example:

# Rule 1fifc--condition'test "$fifc_group" = files'--preview'bat$fifc_candidate'# Rule 2fifc--condition'test "$fifc_group" = files'--source'fd . --color=always --hidden$HOME'

Here, even if both rules have the same conditions, they won't interfere because fifc has to resolve source commandsbefore the preview commands, so order doesn't matter in this case.

Override builtin rules

If you want to write your own rule based on the same conditions as one of the built-in ones, you can use fifc--order option.It tells fifc to evaluate the rule in a predefined order, so you can set it to 1 to make sure it will be evaluated first.

When omitting the--order, the rule will be declared unordered and will be evaluatedafter all other ordered rules, and all other unordered rules defined before.

All built-in rules are unordered.

Examples

Here is how the built-in rule for file preview/open is implemented:

fifc\# If selected item is a file-n'test -f "$fifc_candidate"'\# bind `_fifc_preview_file` to preview command-p _fifc_preview_file\# and `_fifc_preview_file` when pressing ctrl-o-o _fifc_open_file

Interactively search packages in archlinux:

fifc\-r'^(pacman|paru)(\\h*\\-S)?\\h+'\-s'pacman --color=always -Ss "$fifc_token" | string match -r\'^[^\\h+].*\''\-e'.*/(.*?)\\h.*'\-f"--query ''"\-p'pacman -Si "$fifc_extracted"'

gif usage

Search patterns in files and preview matches when commandline starts with**<pattern> (usingripgrep andbatgrep):

fifc\-r'.*\*{2}.*'\-s'rg --hidden -l --no-messages (string match -r -g\'.*\*{2}(.*)\' "$fifc_commandline")'\-p'batgrep --color --paging=never (string match -r -g\'.*\*{2}(.*)\' "$fifc_commandline") "$fifc_candidate"'\-f"--query ''"\-o'batgrep --color (string match -r -g\'.*\*{2}(.*)\' "$fifc_commandline") "$fifc_candidate" | less -R'\-O 1

gif usage

❤️ Credits

ThanksPatrickF1 (and collaborators!), for the greatfzf.fish plugin which inspired me for the command-based configuration, and from which I copied the ci workflow.

📝 License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp