define-command fzzf -params .. %{ evaluate-commands %sh{

    while [ $# -gt 0 ]; do
        case $1 in
            (-items-cmd)    shift; items_cmd="$1"  ;;
        esac
        shift
    done

    # fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzfgit.kak.XXXXXX)
    # fzfcmd="${fzf_tmp}/fzfcmd"
    # result="${fzf_tmp}/result"

    # (
    #     shell_path="$(command -v sh)"
    #     if [ -n "${shell_path}" ]; then
    #         # portable shebang
    #         printf "%s\n" "#!${shell_path}"
    #         # set SHELL because fzf preview uses it
    #         printf "%s\n" "SHELL=${shell_path}"
    #     fi
    #     # compose entire fzf command with all args into single file which will be executed later
    #     # printf "%s\n" "export FZF_DEFAULT_OPTS=\"${kak_opt_fzf_default_opts:-}\""
    #     printf "%s\n" "cd \"${PWD}\" && $items_cmd | fzf > $result"
    #     printf "%s\n" "evaluate-commands -client ${kak_client} edit -existing $file" | kak -p "${kak_session}"
    #     printf "%s\n" "rm ${fzfcmd}"
    #     printf "%s\n" "fg"
    # ) >> "${fzfcmd}"
    # chmod 755 "${fzfcmd}"

    kill -TSTP $kak_client_pid
    cd `pwd` && $items_cmd | \
    fzf | \
    xargs printf "evaluate-commands -client ${kak_client} edit -existing %s\n" | \
    kak -p
    fg

    # cmd="terminal $fzfcmd"

    # Tells kakoune to open a terminal and run $fzfcmd
    # printf "%s\n" "$fzfcmd"

    # (   while [ -e "${fzfcmd}" ]; do sleep 0.1; done
    #     # printf "%s\n" "evaluate-commands -client ${kak_client} edit -existing ~/out.txt" | kak -p "${kak_session}"
    #     if [ -s "${result}" ]; then
    #         file=$(cat $result)
    #         printf "%s\n" "evaluate-commands -client ${kak_client} edit -existing $file" | kak -p "${kak_session}"

    #     fi
    #     rm -rf $fzf_temp
    # ) > /dev/null 2>&1 < /dev/null &

    # Bring kakoune back into the foreground
}}

# define-command fzf-project %{ fzzf -items-cmd 'fd -tfile' }

# map global user f ':fzf-project<ret>' -docstring 'fzf current project'