Recently I’ve added new feature to my powerline.kak plugin. It allows user to select how to display the bufname
in modeline. It has three options:
full
:
short
:
name
:
I think this can be really helpful, and I know that not everyone is using powerline.kak, and prefer a default modeline, so I’ve decided to share the script here:
declare-option -docstring "shorten the name of the buffer accordingly to the setting.
full - do not shorten buffer name: '/full/path/file'.
short - display short path: '/f/p/file'.
name - only show the file name: 'file'." \
str shorten_bufname_type "short"
declare-option -hidden str bufname
define-command -hidden shorten-bufname %{ set-option buffer bufname %sh{
case "$kak_opt_shorten_bufname_type" in
(full)
printf "%s\n" "${kak_bufname}" ;;
(short)
printf "%s\n" "${kak_bufname}" | perl -pe 's:(?(?<=/)|(?<=^))([^\p{Letter}\p{Digit}]+.|[^/]).+?/:\1/:g' ;;
(name)
printf "%s\n" "${kak_bufname##*/}" ;;
esac
}}
hook global WinDisplay .* shorten-bufname
hook global BufWritePost .* shorten-bufname
hook global BufSetOption shorten_bufname_type=.+ shorten-bufname
hook global WinCreate .* %{
set-option window modelinefmt "%opt{bufname} %val{cursor_line}:%val{cursor_char_column} {{context_info}} {{mode_info}} - %val{client}@[%val{session}]"
shorten-bufname
}
I’ve altered it a bit, so it’s not 1 to 1 copy from the plugin (changed names), but it works exactly the same. I’ve used default modeline in the last hook so you have to modify the modeline to fit your needs.