1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

feat: add clone-term from patrickdag

This commit is contained in:
oddlama 2024-07-07 00:15:49 +02:00
parent b4b21b37fa
commit 29e6fdfdb1
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
3 changed files with 49 additions and 0 deletions

View file

@ -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")"
'';
}

View file

@ -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 {};

View file

@ -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}"