Skip to content

Commit

Permalink
adds leuven theme to kitty, adds toggle custom theme switch kitten, m…
Browse files Browse the repository at this point in the history
…oves all kitty config to separate dir and adjust makefile accordingly.
  • Loading branch information
gzagatti committed Feb 14, 2022
1 parent a28fea4 commit 42b1be7
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 55 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ texlive:
julia:
mkdir -p $(workspace)/.julia/config/
ln -fs $(dotfiles)/startup.jl $(workspace)/.julia/config


$(workspace)/.config/kitty:
mkdir -p $(workspace)/.config/kitty/themes

kitty/%: $(workspace)/.config/kitty
ln -fs $(dotfiles)/$@ $(workspace)/.config/$@

kitty: $(shell find kitty -type f)
27 changes: 27 additions & 0 deletions kitty/imgviewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import List
from pathlib import Path
from kitty.boss import Boss
from kittens.tui.handler import result_handler

def main(args: List[str]) -> str:
pass

@result_handler(no_ui=True)
def handle_result(args: List[str], result: None, target_window_id: int, boss: Boss) -> None:
args = args[1:]
files = []
w = boss.window_id_map.get(target_window_id)
for arg in args:
file = Path(arg).expanduser()
if file.exists():
files.append(file)
if len(files) == 0:
return
try:
imgviewer = next(boss.match_windows(f"title:imgviewer{w.id}"))
except StopIteration:
imgviewer = boss.launch("--window-title", f"imgviewer{w.id}",
"--cwd", "current", "--keep-focus")
imgviewer = next(boss.match_windows(f"title:imgviewer{w.id}"))
imgviewer.write_to_child("export HISTFILE=\r")
imgviewer.write_to_child(f"timg {' '.join(str(f) for f in files)}\r")
59 changes: 4 additions & 55 deletions kitty.conf → kitty/kitty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ listen_on unix:/tmp/mykitty
enable_audio_bell no

map kitty_mod+f4 edit_config_file
map kitty_mod+f5 load_config_file
map kitty_mod+f5 load_config_file
map kitty_mod+f6 debug_config

map ctrl+shift+escape kitty_shell window
Expand Down Expand Up @@ -79,57 +79,6 @@ map ctrl+l kitten pass_keys.py neighboring_window right ctrl+l
# https://github.com/kovidgoyal/kitty/issues/719
map kitty_mod+h launch --type overlay --stdin-source=@screen_scrollback --stdin-add-formatting ~/.local/bin/pager.sh

# colors

# dracula theme with minor modifications
foreground #bbbbbb
background #282a36
selection_foreground #ffffff
selection_background #44475a
url_color #8be9fd

# black
color0 #656b73
color8 #444759

# red
color1 #ff5555
color9 #ff6e6e

# green
color2 #50fa7b
color10 #69ff94

# yellow
color3 #f1fa8c
color11 #ffffa5

# blue
color4 #bd93f9
color12 #d6acff

# magenta
color5 #ff79c6
color13 #ff92df

# cyan
color6 #8be9fd
color14 #a4ffff

# white
color7 #f8f8f2
color15 #ffffff

# Cursor colors
cursor #f8f8f2
cursor_text_color background

# tab bar colors
active_tab_foreground #282a36
active_tab_background #f8f8f2
inactive_tab_foreground #282a36
inactive_tab_background #6272a4

# marks
mark1_foreground #282a36
mark1_background #ff5555
# themes
include current-theme.conf
map kitty_mod+c kitten ./toggle_theme.py
9 changes: 9 additions & 0 deletions kitty/neighboring_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def main():
pass


def handle_result(args, result, target_window_id, boss):
boss.active_tab.neighboring_window(args[1])


handle_result.no_ui = True
49 changes: 49 additions & 0 deletions kitty/pass_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re

from kittens.tui.handler import result_handler
from kitty.fast_data_types import encode_key_for_tty
from kitty.key_encoding import KeyEvent, parse_shortcut


def is_window_app(window, app_id):
info = [p['cmdline'] for p in window.child.foreground_processes]
info.append([window.title])
return any(re.search(app_id, i[0] if len(i) else '', re.I) for i in info)


def encode_key_mapping(key_mapping):
mods, key = parse_shortcut(key_mapping)
event = KeyEvent(
mods=mods,
key=key,
shift=bool(mods & 1),
alt=bool(mods & 2),
ctrl=bool(mods & 4),
super=bool(mods & 8),
hyper=bool(mods & 16),
meta=bool(mods & 32),
).as_window_system_event()

return encode_key_for_tty(
event.key, event.shifted_key, event.alternate_key, event.mods, event.action
)


def main():
pass


@result_handler(no_ui=True)
def handle_result(args, result, target_window_id, boss):
window = boss.window_id_map.get(target_window_id)
direction = args[2]
key_mapping = args[3]
app_id = args[4] if len(args) > 4 else "(n?vim|emacs)"

if window is None:
return
if is_window_app(window, app_id):
encoded = encode_key_mapping(key_mapping)
window.write_to_child(encoded)
else:
boss.active_tab.neighboring_window(direction)
52 changes: 52 additions & 0 deletions kitty/themes/dracula.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# dracula theme with minor modifications
foreground #bbbbbb
background #282a36
selection_foreground #ffffff
selection_background #44475a
url_color #8be9fd

# black
color0 #656b73
color8 #444759

# red
color1 #ff5555
color9 #ff6e6e

# green
color2 #50fa7b
color10 #69ff94

# yellow
color3 #f1fa8c
color11 #ffffa5

# blue
color4 #bd93f9
color12 #d6acff

# magenta
color5 #ff79c6
color13 #ff92df

# cyan
color6 #8be9fd
color14 #a4ffff

# white
color7 #f8f8f2
color15 #ffffff

# Cursor colors
cursor #f8f8f2
cursor_text_color background

# tab bar colors
active_tab_foreground #282a36
active_tab_background #f8f8f2
inactive_tab_foreground #282a36
inactive_tab_background #6272a4

# marks
mark1_foreground #282a36
mark1_background #ff5555
54 changes: 54 additions & 0 deletions kitty/themes/leuven.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# leuven theme
foreground #333333
background #f8fbf8
selection_foreground #000000
selection_background #8ed3ff
url_color #006daf

# black
color0 #000000
color8 #000000

# red
color1 #cd0000
color9 #ffe6e4

# green
color2 #228b22
color10 #00cd00

# yellow
color3 #cdcd00
color11 #fff68f

# blue
color4 #0000ff
color12 #0000ee

# magenta
color5 #cd00cd
color13 #cd00cd

# cyan
color6 #00bfff
color14 #00cdcd

# white
color7 #7f7f7f
color15 #ffffff

# Cursor colors
cursor #0fb300
cursor_text_color #000000

# tab bar colors
# active_tab_foreground #282a36
# active_tab_background #f8f8f2
# inactive_tab_foreground #282a36
# inactive_tab_background #6272a4

# marks
#282a36
# mark1_foreground
#ff5555
# mark1_background
28 changes: 28 additions & 0 deletions kitty/toggle_theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import filecmp
from typing import List
from pathlib import Path
from kitty.boss import Boss
from kittens.tui.handler import result_handler
from kitty.constants import config_dir
from kitty.utils import reload_conf_in_all_kitties

def main(args: List[str]) -> None:
pass

@result_handler(no_ui=True)
def handle_result(args: List[str], result: None, target_window_id: int, boss: Boss) -> None:
current_theme = Path(config_dir) / "current-theme.conf"
dracula = Path(config_dir) / "themes/dracula.conf"
leuven = Path(config_dir) / "themes/leuven.conf"
if current_theme.is_symlink():
current_theme.unlink()
if not Path.exists(current_theme):
current_theme.touch()
if dracula.exists() and leuven.exists() and not filecmp.cmp(current_theme, leuven):
current_theme.write_text(leuven.read_text())
elif dracula.exists():
current_theme.write_text(dracula.read_text())
reload_conf_in_all_kitties()



0 comments on commit 42b1be7

Please sign in to comment.