Starship for kakoune

Hi,

powerline.kak is an example of well designed, documented and modulable plugin for kakoune but I was missing an extended git status and other things I liked with my starship prompt. I was too lazy to make a powerline.kak module so I was wondering if it would be possible quickly to make an executable using starship library in rust.

I quickly realized that starship could work pretty decently out of the box with kakoune. You just have to tell starship to use a dedicated config with the STARSHIP_CONFIG env var, use a selected list of plugins, remove all styles (to not have ansi code in the modeline), and insert face syntax in the prompt.

# Use starship to format the modeline
hook global WinCreate .* %{
    hook window NormalIdle .* %{
            evaluate-commands %sh{
                    prompt=$(cd $(dirname $kak_buffile) && STARSHIP_CONFIG=~/.config/kak/starship.toml starship prompt)
                    printf 'set window modelinefmt %%{%s}' "${prompt}"
            }
    }
}

and with following ~/.config/kak/starship.toml config file you have time, battery, memory, rust, directory icons, …

add_newline = false
format = "%val{cursor_line}:%val{cursor_char_column} {{mode_info}} {{context_info}} {builtin}$directory/$custom{meta}$package$rust{keyword}$git_branch$git_commit$git_state{operator}$git_status{value} %val{client}:%val{session} {comment}$memory_usage{module}$battery{mono}$time"

[time]
disabled = false
format = "[ $time ]($style)"
time_format = "%T"
style = ""

[git_branch]
format = ' [$symbol$branch]($style) '
symbol = ' '
# style = 'green'
style = ''
truncation_length = 9223372036854775807
truncation_symbol = '…'
only_attached = false
always_show_remote = true
disabled = false

[git_commit]
commit_hash_length = 7
format = '[\($hash$tag\)]($style) '
# style = 'green bold'
style = ''
only_detached = true
disabled = false
tag_symbol = ' '
tag_disabled = true

[git_state]
rebase = 'REBASING'
merge = 'MERGING'
revert = 'REVERTING'
cherry_pick = 'CHERRY-PICKING'
bisect = 'BISECTING'
am = 'AM'
am_or_rebase = 'AM/REBASE'
# style = 'bold yellow'
style = ''
format = '\([$state( $progress_current/$progress_total)]($style)\) '
disabled = false

[git_status]
format = '([\[$all_status$ahead_behind\]]($style) )'
# style = 'red bold'
style = ''
stashed = '\$'
ahead = '⇡${count}'
behind = '⇣${count}'
diverged = '⇕⇡${ahead_count}⇣${behind_count}'
conflicted = '='
deleted = '✘'
renamed = '»'
modified = '!'
staged = '+'
untracked = '?'
disabled = false

[directory]
truncation_length = 3
truncate_to_repo = false
fish_style_pwd_dir_length = 0
use_logical_path = true
format = '[$path]($style)[$read_only]($read_only_style)'
# style = 'bold bright-red'
style = ''
disabled = false
read_only = '[]'
# read_only_style = 'red'
read_only_style = ''
truncation_symbol = ''

[directory.substitutions]
"~/Nextcloud" = " "
"~/Videos" = " "
"~/Pictures" = " "
"~/Music" = " "
"~/Downloads" = " "
"~/Desktop" = " "
"~/Sync" = "מּ "
"~/.workspace/rust" = ""
"~/.workspace/docker" = " "
"~/.workspace/alpine" = " "
"~/.workspace/arch" = " "
"~/.workspace/kustomize" = "ﴱ "
"~/.workspace/node" = ""
"~/.workspace" = " "
"~/scm" = " "
"~" = " "

[rust]
format = '[$symbol$version]($style)'
version_format = 'v${raw}'
# symbol = '🦀 '
symbol = ' '
# style = 'bold red'
style = ''
disabled = false
detect_extensions = ['rs']
detect_files = ['Cargo.toml']
detect_folders = []

[package]
format = '[$symbol$version]($style) '
symbol = ' '
# style = '208 bold'
style = ''
display_private = false
disabled = false

[battery]
format = "[$symbol]($style) "
# style = 'red bold'
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 10
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 20
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 30
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 40
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 50
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 60
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 70
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 80
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 90
style = ''
charging_symbol = ''
discharging_symbol = ''

[[battery.display]]
threshold = 99
style = ''
charging_symbol = ''
discharging_symbol = ''

[memory_usage]
format = "$symbol [${ram}( | ${swap})]($style) "
disabled = true
threshold = -1
symbol = ''
# style = "bold dimmed green"
style = ''

[custom.kakfile]
command = 'basename $kak_buffile'
when = '[ -n "$kak_buffile" ]'
shell = ['sh']
description = 'The current Kakoune buffername'
style = ''
format = '[$symbol $output]($style)'
7 Likes

I… don’t think so :smiley: but thanks!

You can always submit a feature request, I’m pretty open for new ideas. Thought, I don’t know what exactly starship is, but we can always discuss the implementation details as we go :wink:

Hi andre. I used powerline.kak during a long time and really liked it. I just broke my kakrc after an upgrade (I’m also an happy plug.kak user), so I looked at a way to unify my prompt between kakoune and shell, specially with connect.kak or connect.rc where I found myself coming back and forth between shell and kakoune more often than before. Reuse my starship config made sense to me, and I just made a thin-wrapper around it basically to turn ansi-code into face definition: kakship. It’s just a hack and a commodity, very far away from the cleverness I found reading your powerline.kak code. Thanks again.

Fot those interested, I just wrote a quick wrapper around starship in rust to turn the ansi-code generated by starship into kakoune faces. You can directly style the segments using starship syntax. Also the configuration is now easier to read with the use of custom segments definitions for kakoune.

kakship

The right way would have been to define a pseudo shell KAKOUNE and teach starship to issue the faces definition itself, but not sure the project would ever be interested by such a niche usage. So I made this hack.

There is a simple kakship.kak script that glue everything together.

Regards.

5 Likes

Honestly, this is great, and way better than what powerline.kak does!

starship is a nice piece of software. I think i can learn a thing or two from you if you don’t mind. I didn’t know any clever way to escape % in the starship prompt, so I just replace val{ (removed the % from the starship.toml) with %val{ and % with %%. I’m sure there is a lot of corner cases. I just found one with battery %. Also the kakoune scripts looks too simple to me. I’m not even sure I’m using the suitable hooks… Any advice is welcome. As I said, it’s just 60 rust lines hack.

1 Like

I just removed the dumb escaping and use a proper iterator to skip %opt{, %val{, %sh{ and %{ which can be used “as is” in the toml config. Must be other corner cases though.

1 Like