diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2049d8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +kitty-dump.json +saved-session.conf diff --git a/keymaps.conf b/keymaps.conf index a06150e..bd28702 100644 --- a/keymaps.conf +++ b/keymaps.conf @@ -29,17 +29,26 @@ # `...' ### Keymaps ### +# Markers: Add/remove map f1 create_marker map f2 remove_marker +# Toggle default markers map f3 toggle_marker itext 2 ERROR 1 WARNING 3 PASS + +# Save the current session +map f11 launch --type=background ~/.config/kitty/save_session/save_session.sh + +# Reload config map f12 load_config_file +# Clipboard functions map kitty_mod+c copy_to_clipboard map kitty_mod+v paste_from_clipboard map kitty_mod+s paste_from_selection map shift+insert paste_from_selection map kitty_mod+o pass_selection_to_program +# Tab switching map kitty_mod+right next_tab map ctrl+tab next_tab map kitty_mod+right next_tab diff --git a/save_session/kitty-convert-dump.py b/save_session/kitty-convert-dump.py new file mode 100755 index 0000000..0f94f5d --- /dev/null +++ b/save_session/kitty-convert-dump.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" +this tool is used to convert Kitty session dump to Kitty session file which can be loaded by Kitty +""" + +import json +import os +import sys + + +def env_to_str(env): + """Convert an env list to a series of '--env key=value' parameters and return as a string.""" + s = "" + for key in env: + s += f"--env {key}={env[key]} " + + return s.strip() + + +def cmdline_to_str(cmdline): + """Convert a cmdline list to a space separated string.""" + s = "" + for e in cmdline: + s += f"{e} " + + return s.strip() + + +def fg_proc_to_str(fg): + """Convert a foreground_processes list to a space separated string.""" + s = "" + fg = fg[0] + + # s += f"--cwd {fg['cwd']} {cmdline_to_str(fg['cmdline'])}" + s += f"{cmdline_to_str(fg['cmdline'])}" + + if s == "kitty @ ls": + return os.getenv("SHELL") + return s + + +def convert(session): + """Convert a kitty session dict, into a kitty session file and output it.""" + first = True + for os_window in session: + if first: + first = False + else: + print("\nnew_os_window\n") + + for tab in os_window["tabs"]: + print("\n") + print(f"new_tab {tab['title']}") + # print('enabled_layouts *) + print(f"layout {tab['layout']}") + # This is a bit of a kludge to set cwd for the tab, as + # setting it in the launch command didn't work, for some reason? + if tab["windows"]: + print(f"cd {tab['windows'][0]['cwd']}") + + for w in tab["windows"]: + print(f"title {w['title']}") + print( + f"launch {env_to_str(w['env'])} {fg_proc_to_str(w['foreground_processes'])}" + ) + if w["is_focused"]: + print("focus") + + +if __name__ == "__main__": + stdin = sys.stdin.readlines() + session = json.loads("".join(stdin)) + convert(session) diff --git a/save_session/save_session.sh b/save_session/save_session.sh new file mode 100755 index 0000000..94401af --- /dev/null +++ b/save_session/save_session.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +# Dump the current kitty session: +kitty @ ls >~/.config/kitty/save_session/kitty-dump.json +# Convert this JSON file into a kitty session file: +cat kitty-dump.json | python3 ~/.config/kitty/save_session/kitty-convert-dump.py >~/.config/kitty/sessions/saved-session.conf +# Close the generator window: