Skip to content
Hao Deng edited this page Aug 22, 2018 · 27 revisions

Find

def find -params 1 -shell-candidates %{ find -type f } %{ edit %arg{1} }

Git

def git-edit -params 1 -shell-candidates %{ git ls-files } %{ edit %arg{1} }

FZF

fzf is a basic fuzzy finder tool used to interactively filter large lists of data in a shell.

In the following snippets, a tmux pane is opened with fzf ready to filter a list of files and a list of current buffers.

Other kakoune lists could be filtered this way, taking fzf.vim as inspiration.

def -docstring 'invoke fzf to open a file' \
  fzf-file %{ %sh{
    if [ -z "$TMUX" ]; then
      echo echo only works inside tmux
    else
      FILE=$(find * -type f | fzf-tmux -d 15)
      if [ -n "$FILE" ]; then
        printf 'eval -client %%{%s} edit %%{%s}\n' "${kak_client}" "${FILE}" | kak -p "${kak_session}"
      fi
    fi
} }
# the original version no longer works since kak_buflist is no longer ":" separated.
# this one works if you don't have single quote in file names.

def -override -docstring 'invoke fzf to select a buffer' \
  fzf-buffer %{eval %sh{
      BUFFER=$(printf %s\\n ${kak_buflist} | sed "s/'//g" |fzf-tmux -d 15)
      if [ -n "$BUFFER" ]; then
        echo buffer ${BUFFER}
      fi
} }

Rofi

Select an open buffer using Rofi

define-command rofi-buffers \
-docstring 'Select an open buffer using Rofi' %{ %sh{
    BUFFER=$(printf %s\\n "${kak_buflist}" | tr : '\n' | rofi -dmenu)
    if [ -n "$BUFFER" ]; then
    	echo "eval -client '$kak_client' 'buffer ${BUFFER}'" | kak -p ${kak_session}
    fi
} }  

Using Ag + Rofi to select files in your project directory.

define-command rofi-files \
-docstring 'Select files in project using Ag and Rofi' %{ %sh{
    FILE=$(ag -g "" | rofi -dmenu)
    if [ -n "$FILE" ]; then
        printf 'eval -client %%{%s} edit %%{%s}\n' "${kak_client}" "${FILE}" | kak -p "${kak_session}"
    fi
} }

Fast file finder: fasd integration

Add function k () kak `fasd -f $1` to your .zshrc to open frecent files with k filename

Clone this wiki locally