I’ve been using the following fish alias fzl (“fuzzy list”) to run fzf (“fuzzy find”) in the current directory with a bat preview. It’s just a couple of light tweaks to the examples listed in the fzf README.


function fzl
    # `bat` is aliased to `batcat` on Debian
    if type -q batcat
        set -f bat_command "batcat"
        set -f bat_command "bat"

    # Set the overall width of the `bat` preview to
    # 50% the width of the current terminal
    set -l bat_width $(math ceil $COLUMNS x 0.5)

    # My preferred `bat` options
    set -f bat_command \
        $bat_command \
        --style numbers \
        --color always \
        --italic-text always \
        --wrap auto \
        --terminal-width $bat_width

    fzf \
        --preview "$bat_command {}" \
        --preview-window right,$bat_width,nowrap

Example below.

A screengrab of the terminal output produced by fzl.fish. It shows a list of filenames corresponding to posts on this blog; the post title "Thesis defense" is highlighted.