macoszshfzf

how to use custom preview function for fzf command on zsh


foo() {
    echo "bar"
}
export -f foo

fzf --preview "foo"

leads to opened preview window and error msg:

zsh:1: command not found: foo

How can I define my custom function that can be used for generating the preview?


Solution

  • found (ugly) workaround for zsh:

    1. put all the functions that should be called from --preview to its own file - let's call this preview_functions.sh

    preview_functions.sh:

    foo() {
        echo "bar"
    }
    
    1. use it in the following way:
    fzf --preview "source preview_functions.sh && foo"
    

    ..pretty ugly, but now I am getting the bar in the preview. Thanks F. Hauri for pointing me to a right direction, zsh != bash

    This alsow works - https://unix.stackexchange.com/a/406781/26894 but I don't want to mess my .zshenv