Base16 shell vs kak


#1

very new kak user. I currently use base16-shell to manage my terminal theme. It seems that kak emits it’s own codes to change the colors when it launches. Fine, but it doesn’t restore the prior shell colours when it exits. I’ve tried adding a hook on KakBegin and also on KakEnd to get my colors back in kak itself or at least when it quits, but to no avail. Can anyone help me to ideally: 1. Stop kak from overwrite my colours, or failing that 2. at least restore them on exit. The hooks below replicated what’s in my fish config but don’t seem to do anything helpful.

EDIT: actually it seems that it is on exit that the colours get wiped out, not on startup.

hook global KakBegin .* 'nop %sh{
  sh /home/ben/.base16-manager/chriskempson/base16-shell/scripts/base16-gruvbox-dark-hard.sh
}'

hook global KakEnd .* 'nop %sh{
  sh /home/ben/.base16-manager/chriskempson/base16-shell/scripts/base16-gruvbox-dark-hard.sh 
}'

#2

Hello,

On terminal supporting palette changes, Kakoune touches the palette to set-up color schemes (on other terminals, it approximates the colors requested according to what it believes to be the default palette).

In order to avoid leaving the terminal with a strange palette, on exit it emits an escape sequence to tell the terminal to reset its palette, leading to what you experienced (terminal palette being reset to default after running Kakoune).

Using a KakEnd hook is a good idea there, but will only work on the server process (if you just run one Kakoune client/server process, then you are fine, but if you connect to an existing session with kak -c <session>, KakEnd will not help as you would want that palette restoring code to run on the client terminal.


#3

Actually there is no way that KakEnd hook would work, %sh{...} run in a shell forked from Kakoune which has stdin/out/err redirected to Kakoune itself, so it cannot write to the terminal. You can fix that by redirecting it to /dev/tty to force writing to the current terminal, but as said before, it will only work when the client and server are running on the same terminal.


#4

Durrrr. Of course.

Hurmf. This is totally reasonable and makes perfect sense, it just doesn’t help me :smiley: This doesn’t seem to have a great solution. I guess I could do something janky like run kak inside a shell that runs base16-shell on exit. Or change the way I manage shell colours. Probably the latter.


#5

You can create a function in your shell, something like this:

kak() {
    command kak $@
    base16-shell theme
}

Of course it is ugly hack, but, you know, it can be used, I guess


#6

Thanks, I considered something like that, I have a bunch of patched up commands already, but I think in this instance it’s perhaps time to look at a different way of styling my term (and termite has a base16 template so this will probably be for the best in the longer term).


#7

I use termite, and I’ve specified all colors in configuration file. But I’ve designed a theme for Kakoune to match terminal theme too.