GithubHelp home page GithubHelp logo

eburghar / kakship Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 4.0 194 KB

Thin wrapper around starship.rs to format kakoune status line

Home Page: https://git.itsufficient.me/rust/kakship

License: Apache License 2.0

Rust 55.10% KakouneScript 44.90%
kakoune plugin starship rust statusbar

kakship's Introduction

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 and end 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).

If you need access to kakoune variables in your segments, don't forget to add its name prefixed by kak_opt_ as a comment in kakship.kak file, otherwise it will not be exported to starship process.

		# trigger var export: kak_buffile, kak_session, kak_client, kak_config, kak_cursor_line, kak_buf_line_count
		#                     kak_opt_lsp_diagnostic_error_count, kak_opt_lsp_diagnostic_warning_count,
		#                     kak_opt_lsp_diagnostic_hint_count

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
[custom.kaklsp_hint]
description = "Show hints number from kak-lsp if any"
format = "[ ﯦ %opt{lsp_diagnostic_hint_count}]($style)"
style = "yellow bold"
when = '[ -n "$kak_opt_lsp_diagnostic_hint_count" -a "$kak_opt_lsp_diagnostic_hint_count" -ne 0 ]'
shell = ['sh']
disabled = false
[custom.kaklsp_code_actions]
description = "Show lsp code actions if any"
format = "[ %opt{lsp_modeline_code_actions} ]($style)"
style = "yellow bold"
when = '[ -n "$kak_opt_lsp_modeline_code_actions" ]'
shell = ['sh']
disabled = true
[custom.kaklsp_progress]
description = "Show activity of kak-lsp if any"
format = "[ ]($style)"
style = "bright-white bold"
when = '[ -n "$kak_opt_lsp_modeline_progress" ]'
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.

kakship's People

Contributors

eburghar avatar tomkpz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kakship's Issues

Segment idea: list all opened buffers on the bar

Just like the bufline in vim and helix, it would be nice to create a segment to show opened buffers on the tabline.

The info seems to be available on %val{buflist}

Something like

[custom.kakbuflist]
description = "Open buffers"
format = "[ %val{buflist} ]($style)"
style = "fg:white"
when = ''
shell = ['true']
disabled = false

this is how it looks like

2023-09-19_14-26

Any idea on how do I make it better?

  • format the quoted list returned by buflist
  • omit the current opened buffer from list, as it already shows on the other segment
  • omit the debug buffer
  • add a marker to modified buffers

about the when directive

Hi, I'm trying out your plugin, and was wondering if there is a way to update a segment every 3 seconds or something like that.

thanks :)

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.