dotfiles/.config/kak/autoload/title.kak

88 lines
3.1 KiB
Text

# TODO: make the operation async!
# Is there something we can do with global vs. window scoped title?
declare-option bool bar_debug false
declare-option -docstring %{
Format string passed to printf for the bufferlist.
It should be set in the global scope.
It receives two string arguments, where the first is the buffer index,
and the second is the buffer name.
Default: '[%s %s]'
} str bar_active_fmt '[%s %s]'
declare-option -docstring %{
Format string passed to printf for the bufferlist.
It should be set in the global scope.
It receives two string arguments, where the first is the buffer index,
and the second is the buffer name.
Default: '[%s %s]+'
} str bar_active_modified_fmt '[%s %s]+'
declare-option -docstring %{
Format string passed to printf for the bufferlist.
It should be set in the global scope.
It receives two string arguments, where the first is the buffer index,
and the second is the buffer name.
Default: '%s %s'
} str bar_inactive_fmt '%s %s'
declare-option -docstring %{
Format string passed to printf for the bufferlist.
It should be set in the global scope.
It receives two string arguments, where the first is the buffer index,
and the second is the buffer name.
Default: '%s %s+'
} str bar_inactive_modified_fmt '%s %s+'
define-command -hidden bar-buflist %{
nop %sh{
{
if [ -z "$kak_client" ]; then
exit
fi
list=''
index=0
while read buf; do
if [ "$buf" = '*debug*' ]; then
continue
# foo=bar
fi
index=$((index + 1))
if [ "$buf" = "$kak_bufname" ]; then
if [ "$kak_modified" = "true" ]; then
cur=$(printf "$kak_opt_bar_active_modified_fmt" "$index" "$buf")
else
cur=$(printf "$kak_opt_bar_active_fmt" "$index" "$buf")
fi
else
cur=$(printf "$kak_opt_bar_inactive_fmt" "$index" "$buf")
fi
list="$list $cur"
done <<EOF
$(printf '%s\n' "$kak_buflist" | awk '{gsub(/\*[^*]+\*|[^[:space:]]+/,"&\n"); print}')
EOF
title="$list - $kak_client@[$kak_session]"
# printf "eval -verbatim set-option -add window ui_options %%{terminal_title=%s}" "$title" | kak -p ${kak_session}
title_cmd=$(printf "eval -try-client '$kak_client' -verbatim set-option -add global ui_options %%{terminal_title=%s}" "$title")
echo "$title_cmd" | kak -p ${kak_session}
refresh_cmd=$(printf "eval -verbatim try %%{ exec -try-client '$kak_client' <c-l> }")
echo "$refresh_cmd" | kak -p ${kak_session}
if [ "$kak_opt_bar_debug" = "true" ]; then
printf 'echo -debug -- %s' "$title_cmd" | kak -p ${kak_session}
printf 'echo -debug -- %s' "$refresh_cmd" | kak -p ${kak_session}
fi
} > /dev/null 2>&1 < /dev/null &
}
}
set global bar_debug true
hook global WinDisplay .* bar-buflist
hook global FocusIn .* bar-buflist
# hook global FocusOut .* bar-buflist
hook global WinCreate .* bar-buflist
hook global BufWritePost .* bar-buflist
# hook global ModeChange .* bar-buflist
# hook global NormalIdle .* bar-buflist