Skip to content
Bruno Heridet edited this page Mar 8, 2018 · 2 revisions

The following example is very rough and brittle. Use it as a source of inspiration to hack your own solution.

In this PR, a C++ solution is proposed to embed a buffer list bar in the default ncurses UI.

This wiki page offers an alternative working with stock Kakoune and rely on peripheral tools to achieve the same.

The main trick is to use an external status bar. They are usually used to display information about the OS (memory, network usage…). But most of them accept arbitrary text on stdin. So, we can write a small .kak script that pipe information to it using a FIFO.

Script

In this example we use lemonbar a small (~1000 lines of C using XCB) to display what we want. 3 cores commands are provided:

  • bar-create to make a FIFO and start a lemonbar instance in the background
  • bar-refresh that takes an argument and send the text to lemonbar
  • bar-destroy that remove the FIFO (it should destroy lemonbar but it's not done here, feel free to fix that part)

Then you can build your own commands like bar-refresh-buflist. This one focus on the buffer lit but it can be anything, like stuffs related to the current mode (Normal, Insert), git branches, debugger…

declare-option str barcmd 'lemonbar'
declare-option str bar_buflist

define-command bar-create %{
  %sh{
    {
      fifo=/tmp/kakoune/bar_$kak_session
      rm "$fifo"
      mkfifo "$fifo"
      exec 3<> "$fifo"
      cat "$fifo" | $kak_opt_barcmd -p -B '#282a36' -F '#f8f8f2' -f 'Monospace:size=9' &
    } >/dev/null 2>&1 </dev/null &
  }
  bar-refresh-buflist
}

define-command bar-refresh -params 1 %{
  %sh{
    fifo=/tmp/kakoune/bar_$kak_session
    if [ -p "$fifo" ]; then
      echo "$1" > "$fifo"
    fi
  }
}

define-command bar-destroy %{ %sh{
  fifo=/tmp/kakoune/bar_$kak_session
  rm "$fifo"
} }

hook global KakEnd .* %{ %sh{
  bar-destroy
} }

# Example with buflist

define-command -hidden bar-bufflist %{
  %sh{
    list=''
    while read buf; do
      index=$(($index + 1))
      if [ "$buf" = "$kak_bufname" ]; then
        # markup specific to lemonbar
        list="$list %{R} $index $buf %{R}"
      else
        list="$list  $index $buf "
      fi
    done <<< $(printf '%s\n' "$kak_buflist" | tr ':' '\n')
    echo "set-option global bar_buflist '$list'"
  }
}

define-command bar-refresh-buflist %{
  bar-bufflist
  bar-refresh %opt{bar_buflist}
}

# Suggested hooks

hook global WinDisplay .* bar-refresh-buflist

Screenshot

On this screenshot, kakoune is displayed on the left side of the screen and fzf with preview window on the right side (workspace managed by i3). What's relevant to this wiki page, is the lemonbar on the top which is synchronized with kakoune: every time you do a buffer-next it refreshes accordingly. By using kakoune-buffers you can even type b2 to jump to buffer.cc for example.

All tools use the dracula color theme to give a coherent and seamless experience.

link for bigger image lemonbar + kakoune

Clone this wiki locally