Home

Awesome

<div align="center">

fifc 🐠

fish fzf completions

CI

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

</div>

gif usage

✅ Requirements

✨ Features

🚀 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 override tab, but you can assign another keybinding:

# Bind fzf completions to ctrl-x
set -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:

Show hidden file by default:

⚠️ 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 the fifc command. Actually, all builtin rules are added this way: see conf.d/fifc.fish

See fifc -h for more details.

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

A condition can be either:

If conditions are met, you can bind custom commands:

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 the extracted 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 set fifc_group with the following conditions:

GroupCondition
directoriesAll completion items are directories
filesItems can be either files or 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 1
fifc -n 'test "$fifc_group" = files' -p 'bat $fifc_candidate'
# Rule 2
fifc -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 1
fifc --condition 'test "$fifc_group" = files' --preview 'bat $fifc_candidate'
# Rule 2
fifc --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 commands before 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 evaluated after 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> (using ripgrep and batgrep):

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

Thanks PatrickF1 (and collaborators!), for the great fzf.fish plugin which inspired me for the command-based configuration, and from which I copied the ci workflow.

📝 License

MIT