This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / tmux / flake-module.nix
2.6 kB 67 lines
1{ self, inputs, ... }: 2{ 3 perSystem = 4 { pkgs, ... }: 5 let 6 sessionManager = pkgs.writeShellScript "tmux-session-manager" '' 7 while true; do 8 existing=$(tmux list-sessions -F '#{session_name}: #{session_windows} windows (created #{session_created_string})#{?session_attached, (attached),}' 2>/dev/null) 9 [[ -z "$existing" ]] && break 10 chosen=$(echo -e ">>> new session <<<\n$existing" \ 11 | ${pkgs.fzf}/bin/fzf --height=80% --reverse \ 12 --header="Pick a tmux session (DEL to kill)" \ 13 --expect=delete \ 14 --preview='s={1}; s=''${s%:}; [ "$s" = ">>>" ] && echo "Create a new session" || tmux capture-pane -t "$s" -p -e 2>/dev/null' \ 15 --preview-window=down:50%) 16 key=$(echo "$chosen" | head -1) 17 selection=$(echo "$chosen" | tail -1) 18 chosen_name=$(echo "$selection" | cut -d: -f1) 19 if [[ "$key" == "delete" && -n "$chosen_name" && "$chosen_name" != ">>> new session <<<" ]]; then 20 tmux kill-session -t "$chosen_name" 2>/dev/null 21 continue 22 fi 23 if [[ -n "$chosen_name" && "$chosen_name" != ">>> new session <<<" ]]; then 24 tmux switch-client -t "$chosen_name" 25 exit 0 26 fi 27 break 28 done 29 # Create a new session 30 session_name=$(${ 31 self.packages.${pkgs.system}.name-generator 32 }/bin/name-generator 2>/dev/null || echo "session-$$") 33 tmux new-session -d -s "$session_name" 34 tmux switch-client -t "$session_name" 35 ''; 36 tmuxConfigText = '' 37 set-option -g default-terminal screen-256color 38 39 # Auto-destroy sessions when no clients attached (handles terminal close) 40 set -g destroy-unattached on 41 42 # Enable kitty graphics protocol passthrough 43 set -g allow-passthrough on 44 set -ga update-environment TERM 45 set -ga update-environment TERM_PROGRAM 46 47 # Session manager popup (prefix + s) 48 bind s display-popup -E -w 80% -h 80% "${sessionManager}" 49 ''; 50 tmuxConfigFile = pkgs.writeText "tmux.conf" tmuxConfigText; 51 in 52 { 53 packages.tmux = 54 (inputs.wrappers.lib.wrapPackage { 55 pkgs = pkgs; 56 package = pkgs.tmux; 57 flags = { 58 "-f" = "${tmuxConfigFile}"; 59 }; 60 }).overrideAttrs 61 (old: { 62 passthru = (old.passthru or { }) // { 63 tmuxConfig = tmuxConfigText; 64 }; 65 }); 66 }; 67}