Basic commands with FZF and Ripgrep

Hello.

I have been wanting to just have some simple commands with FZF and Ripgrep.

I’m running into the issue of FZF coming up with 0 results for this command.

define-command -params 0..2 -file-completion \
    -docstring "Find and edit files with fzf. You can also pass a UNIX glob." \
    files %{
    evaluate-commands %sh{
        glob="$1"
        dir="$2"
        if [ -z  "${kak_client_env_TMUX}" ]; then
			printf 'fail "Client was not started under tmux"\n'
	else
            if [ -z "$glob" ]; then
                cmd=rg --files --hidden --no-heading --column --color=auto --smart-case
	    else
	        cmd=rg --files --hidden --no-heading --column --color=auto --glob "$glob" --smart-case
            fi
            if [ -n "$dir" ]; then
	        file=$("$cmd" "$dir" | \
	            TMUX="${kak_client_env_TMUX}" \
		    fzf-tmux --height=30% --reverse --ansi)
	        
	    else
	        file=$("$cmd" "$PWD" | \
		TMUX="${kak_client_env_TMUX}" \
		fzf-tmux --height=30% --reverse --ansi)
	    fi
	    if [ -n $file ]; then
	        printf 'edit "%s"\n' "$file"
	    fi

        fi

    }
}

And how I would call it is say to look at my Kakoune config directory without the plugins/ directory: :files "!.config/kak/plugins/**" ~/.config/kak.

Now the does this just from the command line with

rg --files --hidden --no-heading --column --color=auto --glob "!.config/kak/plugins/**" ~/.config/kak | fzf --reverse --height=30% --ansi

Works fine.

And the example from the Github wiki works fine as well.

All I want is to use this with either 0 to 2 arguments, and those two arguments to be a glob and/or a path to a directory.

Another reason I’m posting this is probably because you all could probably help me make it less sloppy. :stuck_out_tongue:

<self-advertisement>why not fzf.kak? It supports many tools, ripgrep included</self-advertisement>

1 Like

I probably will end up installing fzf.kak at some point, but this is just one of those things I want to figure out for myself.

One thing I found that, instead of supplying a glob for files or paths to ignore, it’s probably easier just to have a .rgignore file.

Hello.

I’ve not (yet) read the code with precision, but could the issue be related to the use of $1 and $2 in the shell block instead of relying on $kak_arg_1 and $kak_arg_2?

Ah, I didn’t know that’s how you use arguments in Kakoune.

I also see if that you’re not using a shell block you use %arg{x}.

Well I’m glad I know now.

main reason for globs is SVN, which has no ignore file, and I work with svn at work a lot. Also handy for excluding build files anywhere