From 911d1c59186304be83d7302905a0a7bbf7de1d99 Mon Sep 17 00:00:00 2001 From: Julian T Date: Fri, 18 Mar 2022 15:20:41 +0100 Subject: Add open_rel script --- i3/.config/i3/config | 2 +- scripts/Scripts/open_rel | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 scripts/Scripts/open_rel diff --git a/i3/.config/i3/config b/i3/.config/i3/config index db8ba4c..4a1db6c 100644 --- a/i3/.config/i3/config +++ b/i3/.config/i3/config @@ -178,7 +178,7 @@ bindsym XF86Display exec ~/Scripts/screentool # launch script thingy bindsym $mod+semicolon exec --no-startup-id Scripts/lc --dmenu -bindsym $mod+o exec --no-startup-id Scripts/lc goto +bindsym $mod+o exec --no-startup-id Scripts/open_rel # Password manager bindsym $mod+p exec --no-startup-id Scripts/lc pass diff --git a/scripts/Scripts/open_rel b/scripts/Scripts/open_rel new file mode 100755 index 0000000..06f246d --- /dev/null +++ b/scripts/Scripts/open_rel @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import re +import subprocess as sp + + +def get_window_title() -> str: + command = ["xdotool", "getactivewindow", "getwindowname"] + ret = sp.run(command, capture_output=True) + + return ret.stdout.decode("utf-8")[:-1] + + +def launch_term(command=None, directory=None): + run = ["i3-sensible-terminal"] + if command: + run.extend(["-e", command]) + if directory: + run.extend(["-d", directory]) + + print("Running:", run) + sp.run(run) + + +def decide_and_run(title: str): + print(title) + if title.startswith("fish "): + launch_term(directory=title[5:]) + elif (m := re.search(".*client\d*@\[(\d*)\] - Kakoune", title)): + id = m.group(1) + launch_term(command=f"kak -c {id}") + + +if __name__ == "__main__": + title = get_window_title() + decide_and_run(title) -- cgit v1.2.3