diff --git a/pkgs/scripts/clone-term.nix b/pkgs/scripts/clone-term.nix new file mode 100644 index 0000000..daea0ad --- /dev/null +++ b/pkgs/scripts/clone-term.nix @@ -0,0 +1,47 @@ +# From: https://forge.lel.lol/patrick/nix-config/src/commit/77e9d0eaf356537131d33389cca15ffdd7bbefc2/pkgs/scripts/clone-term.nix +{ + writeShellApplication, + ps, + procps, + xdotool, + jq, +}: +writeShellApplication { + name = "clone-term"; + runtimeInputs = [ps procps xdotool jq]; + text = '' + + if [[ ''${XDG_CURRENT_DESKTOP-} == sway ]]; then + PAREN=$(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid') + elif [[ ''${XDG_CURRENT_DESKTOP-} == Hyprland ]]; then + PAREN=$(hyprctl activewindow -j | jq '.pid') + else + PAREN=$(xdotool getwindowfocus getwindowpid) + fi + + 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")" + ''; +} diff --git a/pkgs/scripts/default.nix b/pkgs/scripts/default.nix index 461ce01..6f844c5 100644 --- a/pkgs/scripts/default.nix +++ b/pkgs/scripts/default.nix @@ -1,6 +1,7 @@ _final: prev: { scripts = { brightness = prev.callPackage ./brightness.nix {}; + clone-term = prev.callPackage ./clone-term.nix {}; screenshot-area = prev.callPackage ./screenshot-area.nix {}; screenshot-area-scan-qr = prev.callPackage ./screenshot-area-scan-qr.nix {}; screenshot-screen = prev.callPackage ./screenshot-screen.nix {}; diff --git a/users/myuser/graphical/hyprland.nix b/users/myuser/graphical/hyprland.nix index 69aaa88..bf7c752 100644 --- a/users/myuser/graphical/hyprland.nix +++ b/users/myuser/graphical/hyprland.nix @@ -56,6 +56,7 @@ in { ",Menu,exec,${rofi-drun}" "SUPER,t,exec,kitty" "SUPER,b,exec,firefox" + "SUPER,c,exec,${getExe pkgs.scripts.clone-term}" # Shortcuts & Actions "SUPER + SHIFT,s,exec,${getExe pkgs.scripts.screenshot-area}"