From 2d8f41149631f6c68564975c6c6b0b2006ed4763 Mon Sep 17 00:00:00 2001 From: Julian T Date: Fri, 18 Mar 2022 15:36:53 +0100 Subject: Add nixshell to open_rel --- i3/.config/i3/config | 1 + scripts/Scripts/open_rel | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/i3/.config/i3/config b/i3/.config/i3/config index 4a1db6c..632726f 100644 --- a/i3/.config/i3/config +++ b/i3/.config/i3/config @@ -178,6 +178,7 @@ bindsym XF86Display exec ~/Scripts/screentool # launch script thingy bindsym $mod+semicolon exec --no-startup-id Scripts/lc --dmenu +bindsym $mod+Shift+o exec --no-startup-id Scripts/open_rel --shell bindsym $mod+o exec --no-startup-id Scripts/open_rel # Password manager diff --git a/scripts/Scripts/open_rel b/scripts/Scripts/open_rel index 06f246d..6d68c41 100755 --- a/scripts/Scripts/open_rel +++ b/scripts/Scripts/open_rel @@ -3,6 +3,8 @@ import re import subprocess as sp +import argparse + def get_window_title() -> str: command = ["xdotool", "getactivewindow", "getwindowname"] @@ -22,15 +24,31 @@ def launch_term(command=None, directory=None): sp.run(run) -def decide_and_run(title: str): - print(title) +def decide_and_run(title: str, do_shell=True): 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}") + elif (m := re.search("nix-shell ([^ ]*)( +([^ ]*))?", title)): + shell_file = m.group(1) + folder = m.group(3) + if folder is None: + folder = shell_file + shell_file = None + if do_shell: + command = "nix-shell" + (f" {shell_file}" if shell_file else "") + else: + command = None + + launch_term(command=command, + directory=folder) if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--shell", "-s", action="store_true") + args = parser.parse_args() title = get_window_title() - decide_and_run(title) + + decide_and_run(title, args.shell) -- cgit v1.2.3