feat: added terminal cloning

This commit is contained in:
Patrick 2024-05-31 22:15:17 +02:00
parent 9ee470cfb5
commit 518f84e916
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
3 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,39 @@
{
writeShellApplication,
ps,
procps,
xdotool,
}:
writeShellApplication {
name = "clone-term";
runtimeInputs = [ps procps xdotool];
text = ''
PAREN=$(xdotool getwindowfocus getwindowpid)
MAXDEPTH=0
SELECTED=0
function recurse() {
#shellcheck disable=SC2207
for i in $(pgrep -P "$1"); do
if [[ "$(readlink -e "/proc/''${i}/exe")" == *"zsh"* ]] && [[ $2 -gt $MAXDEPTH ]]; then
SELECTED="$i"
MAXDEPTH="$2"
fi
recurse "$i" "$(( $2 + 1 ))"
done
}
recurse "$PAREN" 1
if [[ $SELECTED == 0 ]]; then
echo "not zsh found"
exit 1
fi
# kitty should be from user env
kitty --detach -d "$(readlink "/proc/''${SELECTED}/cwd")"
'';
}

View file

@ -1,5 +1,6 @@
_final: prev: { _final: prev: {
scripts = { scripts = {
usbguardw = prev.callPackage ./usbguardw.nix {}; usbguardw = prev.callPackage ./usbguardw.nix {};
clone-term = prev.callPackage ./clone-term.nix {};
}; };
} }

View file

@ -24,6 +24,7 @@
maim = "${pkgs.maim}/bin/maim -qs -b 1 --hidecursor"; maim = "${pkgs.maim}/bin/maim -qs -b 1 --hidecursor";
in { in {
"Menu" = "exec ${cfg.menu}"; "Menu" = "exec ${cfg.menu}";
"${cfg.modifier}+c" = "exec ${lib.getExe pkgs.scripts.clone-term}";
"Ctrl+F9" = "exec ${config.xsession.wallpapers.script}"; "Ctrl+F9" = "exec ${config.xsession.wallpapers.script}";
"${cfg.modifier}+F12" = "${cfg.modifier}+F12" =
"exec " "exec "