# Base16 shell vs kak

**URL:** <https://discuss.kakoune.com/t/base16-shell-vs-kak/368>\
**Category:** Help\
**Tags:** face\
**Created:** [March 12, 2019, 7:14pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368 "2019-03-12T19:14:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bme](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discuss.kakoune.com/u/bme)\
**Post date:** [March 12, 2019, 7:14pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/1 "2019-03-12T19:14:51Z")

</div>

_very_ new kak user. I currently use [base16-shell](https://github.com/chriskempson/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.

```auto
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 
}'

```

---

<div class="post-metadata">

**Author:** ![mawww](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mawww](https://discuss.kakoune.com/u/mawww)\
**Post date:** [March 12, 2019, 10:45pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/2 "2019-03-12T22:45:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mawww](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@mawww](https://discuss.kakoune.com/u/mawww)\
**Post date:** [March 12, 2019, 10:54pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/3 "2019-03-12T22:54:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bme](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discuss.kakoune.com/u/bme)\
**Post date:** [March 12, 2019, 11:01pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/4 "2019-03-12T23:01:34Z")

</div>

> [@mawww](#):
>
> 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.

Durrrr. Of course.

> [@mawww](#):
>
> 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.

Hurmf. This is totally reasonable and makes perfect sense, it just doesn’t help me 😃 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.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [March 14, 2019, 5:50pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/5 "2019-03-14T17:50:16Z")

</div>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![bme](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discuss.kakoune.com/u/bme)\
**Post date:** [March 14, 2019, 6:58pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/6 "2019-03-14T18:58:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [March 14, 2019, 7:36pm UTC](https://discuss.kakoune.com/t/base16-shell-vs-kak/368/7 "2019-03-14T19:36:53Z")

</div>

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.
