From 35af4bab99da94845ebd6e9b2efae6a544d39b35 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Fri, 22 May 2026 10:23:58 -0500 Subject: LOTS OF TEMP STUFF --- tmux-tsunami/modules/common/sessionizer.nix | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tmux-tsunami/modules/common/sessionizer.nix (limited to 'tmux-tsunami/modules/common/sessionizer.nix') diff --git a/tmux-tsunami/modules/common/sessionizer.nix b/tmux-tsunami/modules/common/sessionizer.nix new file mode 100644 index 0000000..09aa65a --- /dev/null +++ b/tmux-tsunami/modules/common/sessionizer.nix @@ -0,0 +1,92 @@ +{ + pkgs, + config, + lib, + tsunamiLib, + std, + ... +}: let + inherit (tsunamiLib) scriptPath filePath; + cfg = config.tsunami.sessionizer; +in { + options = { + tsunami.sessionizer = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + }; + }; + }; + + config = lib.mkIf cfg.enable { + tsunami.keys.leader = [ + { + name = "Sessions+"; + key = "C-s"; + exec = "run-shell ${scriptPath "sessions-menu"}"; + } + ]; + + tsunami.scripts = { + "sessionizer" = + # bash + '' + [ -z "$1" ] && exit + + selected="$1" + session_name="$(basename "$selected" | tr '.' '_')" + + # if the session doesn't exist, create it + if ! tmux has-session -t "$session_name"; then + tmux new-session -ds "$session_name" -c "$selected" + tmux set-option -t "$session_name" @default-path "$selected" + fi + + # switch to it + tmux switch -t "$session_name" + ''; + "launch-sessionizer" = ''${pkgs.broot}/bin/broot --only-folders --conf ${filePath "broot_sessionizer.toml"}''; + "new-session" = ''tmux switch-client -t "$(tmux new-session -dP)"''; + "sessions-menu" = + # bash + '' + menu_items=( + "Switch Session" s "run-shell '${scriptPath "minibuffer"} -d $HOME ${scriptPath "launch-sessionizer"}'" + "New Unnamed Session" n "run-shell ${scriptPath "new-session"}" + ) + + # put tmux session names into a list + mapfile -t sessions < <(tmux list-sessions -F "#{session_name}") + + # ...but limit at 9 sessions + for i in "''\${!sessions[@]}"; do + (( i >= 9 )) && break # Stop after 9 sessions + + session="''\${sessions[$i]}" + key=$((i + 1)) # 1-based key + + # and put those 9 in the list of menu items + menu_items+=("$session" "$key" "switch-client -t $session") + done + + # Display the menu + ${scriptPath "menu"} -T "#[align=centre]Sessions" "''\${menu_items[@]}" + ''; + }; + tsunami.files = { + "broot_sessionizer.toml" = std.serde.toTOML { + imports = ["~/.config/broot/conf.hjson"]; # inherit from user's config + quit_on_cancel = true; + verbs = [ + { + invocation = "session"; + external = ''bash -c -- "${scriptPath "sessionizer"} '{file}'"''; + key = "enter"; + apply_to = "directory"; + leave_broot = true; + } + ]; + }; + }; + }; +} -- cgit v1.3.1