Thin wrapper around starship.rs to format kakoune status line

Overview

kakship and kakship.kak

kakship is just a thin wrapper around starship to format the status line of kakoune and is meant to be used with the included kakoune script kakship.kak.

kakship prompt

Operating mode

kakship

  • overrides override the default config file path with $kak_config/starship.toml,
  • sets the STARSHIP_SHELL to be sh
  • forwards the given arguments to starship,
  • transforms ansi-codes to kakoune face definitions when called with prompt argument.

It uses a forked yew-ansi crate for parsing the ansi-codes to which I just added support for reversed and dimmed ansi-codes that can be used in starship styles definitions.

The kakoune script call kakship in normal mode when idle for all buffers whose names don't start with *. As starship is really fast and format a prompt in ms, the script doesn't need to be clever about when refreshing the status bar.

Installation

Prerequisites

Manual

  1. Compile kakship with cargo and install it somewhere in your $PATH (for example ~/.local/bin)
cargo install --force --path . --root ~/.local
  1. Copy/modify the provided starship.toml to your $kak_config directory (usually ~/.config/kak/)

  2. Put the kakship.kak script in your autoload path and add something like this to your kakrc

hook global ModuleLoaded kakship .* %{
	kakship-enable
}

With a plugin manager

with plug.kak

plug "eburghar/kakship" do %{
	cargo install --force --path . --root ~/.local
	[ ! -e $kak_config/starship.toml ] && cp starship.toml $kak_config/
} config %{
	kakship-enable
}

Writing custom segments

To write new segments, you can use the custom-commands module of starship. Define a new section with a dot notation [custom.mymodule], and insert a variable with the same name in the topmost format definition (format=...${custom.mymodule}..)

In case you just need string substitutions (like custom.kakmode bellow), you can avoid calling a shell to evaluate the when condition by setting the shell variable to ['true'] and the when variable to ''. In case no $output variable appears in the format definition of the segment, no shell is called, making your segment faster to evaluate.

In case you really need to call an external command, you have 3 choices:

  1. setup shell, command and when and let starship do the evaluation

  2. use kakoune expansion blocks (sh, opt, val, reg, file) inside the format and let kakoune do the evaluation. Note than only curly brace is supported as the quoting char.

  3. a mix of kakoune and starship evaluations

With kakoune expansion the modeline will change as soon as the variable, register, option, value, used in the expression changes and in the case of %sh kakoune will rebuild the modeline every second or so when in normal mode. In other words, the modline will change without ever needing to call kakship. This leads for example to a custom time segment definition (custom.kaktime below) which will show seconds even if the editor is idle, contrary to the starship time module which changes only during pause.

As for the 3rd option, you can use environment variables (starship evaluation) for telling starship when to display a segment, and use a kakoune expansion in the format to let kakoune do the update as soon as possible (see custom.kaklsp_err bellow).

Kakoune segments

Here are some common custom segments for kakoune. I'll be happy to maintain a catalog if you send me a PR.

[custom.kakfile]
description = 'The current Kakoune buffername'
format = '[/$output ]($style)[]($style inverted) '
style = 'bold bg:blue fg:black'
command = 'echo -n ${kak_buffile##*/}'
when = 'true'
shell = ['sh']
disabled = false
[custom.kaksession]
description = 'The current Kakoune session'
format = '[]($style)[  %val{client}:%val{session} ]($style)[]($style inverted)'
style = 'bg:yellow fg:black'
when = ''
shell = ['true']
disabled = false
[custom.kakcursor]
description = 'The current Kakoune cursor position'
format = '[%val{cursor_line}:%val{cursor_char_column}]($style)'
style = 'fg:white'
when = ''
shell = ['true']
disabled = false
[custom.kakmode]
description = 'The current Kakoune mode'
format = ' {{mode_info}}'
when = ''
shell = ['true']
disabled = false
[custom.kakcontext]
description = 'The current Kakoune context'
format = ' {{context_info}}'
when = ''
shell = ['true']
disabled = false
[custom.kakfiletype]
description = 'The current buffer filetype'
format = '\[%opt{filetype}\] '
when = ''
shell = ['true']
disabled = false
[custom.kakposition]
description = 'Relative position of the cursor inside the buffer'
format = '[  $output]($style)'
style = 'bright-white'
command = 'echo -n $(($kak_cursor_line * 100 / $kak_buf_line_count))%'
when = '[ -n "$kak_cursor_line" ]'
shell = ['sh']
disabled = false
[custom.kaktime]
description = "Alternate time segment using kakoune evaluation"
format = "[]($style)[  %sh{date +%T} ]($style)"
style = "fg:black bg:bright-green"
when = ''
shell = ['true']
disabled = false
[custom.kaklsp_err]
description = "Show errors number from kak-lsp if any"
format = "[  %opt{lsp_diagnostic_error_count}]($style)"
style = "red bold"
when = '[ -n "$kak_opt_lsp_diagnostic_error_count" -a "$kak_opt_lsp_diagnostic_error_count" -ne 0 ]'
shell = ['sh']
disabled = false
[custom.kaklsp_warn]
description = "Show warnings number from kak-lsp if any"
format = "[  %opt{lsp_diagnostic_warning_count}]($style)"
style = "yellow bold"
when = '[ -n "$kak_opt_lsp_diagnostic_warning_count" -a "$kak_opt_lsp_diagnostic_warning_count" -ne 0 ]'
shell = ['sh']
disabled = false

Tips

To check if your modeline is not overloaded.

kak_config="~/.config/kak" kakship timings

To check the settings with all modules default values

kak_config="~/.config/kak" kakship print-config

To debug the prompt as set under kakoune

kak_config="~/.config/kak" kakship prompt

References

powerline.kak is another excellent kakoune plugin from Andrey Listopadov devoted to modeline which relies merely on kakscript, has themes and even has an API for defining new plugins.

You might also like...
3MF (3D Manufacturing Format) support for Rust

3MF (3D Manufacturing Format) support for Rust About This library provides support for 3MF files to programs written in the Rust programming language.

CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" format.

Lighthouse Groupie CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" form

A crude tool to convert from Bitwarden json format to lastpass

Pass-Merger A crude tool to convert from Bitwarden json format to lastpass. Steps to Deduplicate entries from Bitwarden Export all passwords from Chro

Ampseer examines reads in fastq format and identifies which multiplex PCR primer set was used to generate the SARS-CoV-2 sequencing library they are read from.

Ampseer examines reads in fastq format and identifies which multiplex PCR primer set was used to generate the SARS-CoV-2 sequencing library they are read from.

🗃 Decoder and utility for the Flipnote Studios .ppm animation format.
🗃 Decoder and utility for the Flipnote Studios .ppm animation format.

🗃 para What? A decoder and utility for the Flipnote Studios .ppm animation format. Why this implementation over the original? This implementation is

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

A lightweight Discord wrapper made in Tauri

Discord-Tauri is a work in progress lightweight wrapper for Discord.

A rust wrapper for the spam protection API
A rust wrapper for the spam protection API

SpamProtection-rs Table of contents About Supported Rust version Features How to use Credits License About This repo has been shifted to the official

A Rust wrapper for the SponsorBlock API.

sponsor-block A Rust wrapper for the SponsorBlock API, which you can find complete documentation for here. Uses SponsorBlock data licensed under CC BY

Comments
  • Run kakship asynchronously

    Run kakship asynchronously

    When working in a large project like Chromium, starship git modules like git_status can take a long time (I've experienced up to a second of delay). Previously, the kakship call was run synchronously, which blocks the editor while the command is running and prevents user input. This change makes the kakship call async so movement is still smooth while the prompt is being created.

    opened by tomKPZ 1
  • Add Cargo.lock

    Add Cargo.lock

    Hey there,

    Thanks for the great status line!

    I'm trying to build this project with Nix, as I use NixOS, but to get that to work I hit an error message:

    > ERROR: The Cargo.lock file doesn't exist
    >
    > Cargo.lock is needed to make sure that cargoHash/cargoSha256 doesn't change
    > when the registry is updated.
    

    Would it be possible for you to create & add a Cargo.lock file to this repo?

    opened by jaredramirez 1
Owner
Eric Burghard
Eric Burghard
cargo-check This is a wrapper around cargo rustc

cargo-check This is a wrapper around cargo rustc -- -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks. In

Ray Solomon 99 Oct 13, 2022
A simple, yet feature-filled wrapper around the coqui-stt C API

A simple, yet feature-filled wrapper around the coqui-stt C API

0/0 56 Jan 3, 2023
A safe wrapper around Gamercade's raw Api.

gamercade-rs A safe wrapper around Gamercade's Raw Api. As the Raw Api requires using a lot of unsafe and hiding of values through different types (fo

null 1 Aug 23, 2022
🌋 A very lightweight wrapper around the Vulkan Memory Allocator 🦀

?? vk-mem-alloc-rs A very lightweight wrapper around the Vulkan Memory Allocator ?? [dependencies] vk-mem-alloc = "0.1.1" Simple Vulkan Memory Allocat

Project KML 13 Nov 8, 2022
Shows my Spotify status on a small screen. Powered by ESP-IDF & built with 🧡 in Rust! 🦀

ESP Display A small embedded project that shows what I'm listening to on Spotify by using my Spotify service. Example Notable Features ESP32-S3 board

Isaiah Gamble 3 Apr 10, 2024
A collection of compilers based around compiling a high level language to a Brainfuck dialect.

tf A collection of compilers based around compiling a high level language to a Brainfuck dialect. Built at, and for, the VolHacks V hackathon during O

adam mcdaniel 6 Nov 25, 2021
A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.

rs-cord A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use. Documentation • Crates.io • Discord Navigation M

Jay3332 4 Sep 24, 2022
A simple library with just one struct which is used to wrap around pointers

A simple library with just one struct which is used to wrap around pointers. This can be used to create pointers and share them across threads without the hassle of synchronization if you really do not care about that.

null 1 Apr 11, 2022
Just a personal Rust Playground to play around and understand the language.

Rust Proactive Introduction The code is a bit messy but it serves just as a personal Rust Playground to play around and understand the language. You c

Fernando Cejas 3 Dec 21, 2022
osu-link is a program which links osu!stable beatmaps to osu!lazer's new store format, saving you disk space.

osu-link is a program which links osu!stable beatmaps to osu!lazer's new store format, saving you disk space.

LavaDesu 2 Nov 8, 2021