From a2c9d90243cab496fa1fc3c64cf8f38fb116969b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 4 Dec 2024 18:54:43 +0100 Subject: [PATCH] Kill tmux session when killing last pane --- hosts/fuhen/hardware-configuration.nix | 2 +- modules/cli/zsh/default.nix | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hosts/fuhen/hardware-configuration.nix b/hosts/fuhen/hardware-configuration.nix index 2521ac0..2596f79 100644 --- a/hosts/fuhen/hardware-configuration.nix +++ b/hosts/fuhen/hardware-configuration.nix @@ -43,7 +43,7 @@ } ]; # use swap only when strictly needed - boot.kernel.sysctl = { "vm.swappiness" = 1; }; + boot.kernel.sysctl = { "vm.swappiness" = 0; }; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's diff --git a/modules/cli/zsh/default.nix b/modules/cli/zsh/default.nix index 1ca6e4b..5281bef 100644 --- a/modules/cli/zsh/default.nix +++ b/modules/cli/zsh/default.nix @@ -237,6 +237,14 @@ # Create a new tmux session (with a random name) and attach. if [[ -z "$TMUX" ]]; then exec tmux -u new-session -s "#$(hexdump -n 4 -v -e '/1 "%02X"' /dev/urandom)" + else + # kill current sesion if we are quiting the only pane + function __onExit { + if [[ $(tmux list-panes -s | wc -l) == 1 ]]; then + tmux kill-session + fi + } + trap __onExit EXIT fi ''; initExtraBeforeCompInit = builtins.readFile ./comp.zsh;