Best practices for "finding executable"

#1

For example, I might want to use ripgrep (rg) if it exists, else platinum search (pt), else silver search (ag) else grep. What is the best way to setup this when used by multiple independents in your kakrc.

#2

As a first approximation, I’d probably try something like:

eval %sh{
    for tool in rg pt ag; do
        if command -V "$tool" >/dev/null 2>/dev/null; then
            printf "set global grepcmd %s\n" "$tool"
        fi
    done
}

Of course, it gets more complex if the different tools need different command-line options (for example, you might want grep -e if all you have is grep, but other tools use extended regexps by default), or you want to look in places other than $PATH.

#3

My configuration defines it like so:

evaluate-commands %sh{
    [ ! -z "$(command -v rg)" ] && printf "%s\n" "set-option global grepcmd 'rg -L --with-filename --column'"
}

Otherwise I use default value here.

For fzf.kak it’s bit more complicated:

plug "andreyorst/fzf.kak" %{
    map -docstring 'fzf mode' global normal '<c-p>' ': fzf-mode<ret>'
    set-option global fzf_preview_width '65%'
    set-option global fzf_project_use_tilda true
    evaluate-commands %sh{
        if [ -n "$(command -v fd)" ]; then
            echo "set-option global fzf_file_command %{fd . --no-ignore --type f --follow --hidden --exclude .git --exclude .svn}"
        else
            echo "set-option global fzf_file_command %{find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -follow -print}"
        fi
        [ -n "$(command -v bat)" ] && echo "set-option global fzf_highlight_cmd bat"
        [ -n "${kak_opt_grepcmd}" ] && echo "set-option global fzf_sk_grep_command %{${kak_opt_grepcmd}}"
    }
}

But uses the same principle.

Find File (improvements needed)