{ writeShellApplication, tmux, procps, symlinkJoin, }: let tmux-register-session = writeShellApplication { name = "__tmux-register-session"; runtimeInputs = [tmux]; text = '' last=/tmp/TMUX_LAST this="$(tmux display-message -p '#S')" if [ ! -f "$last" ] || [ "$(cat "$last")" != "$this" ]; then echo "$this" >"$last" fi ''; }; tmux-maybe-create = writeShellApplication { name = "__tmux-maybe-create"; runtimeInputs = [procps tmux]; text = '' session_name="$1" session_dir="$2" if ! pgrep tmux >/dev/null 2>&1 || ! tmux has -t="$session_name" 2>/dev/null; then tmux new-session -ds "$session_name" -c "$session_dir" fi ''; }; tmux-attach-or-switch = writeShellApplication { name = "__tmux-attach-or-switch"; runtimeInputs = [tmux]; text = '' session_name="$1" TMUX=''${TMUX:-} if [ -z "$TMUX" ]; then tmux attach-session -t "$session_name" else tmux switch-client -t "$session_name" fi ''; }; in symlinkJoin { name = "tmux-sessionizer"; paths = [ tmux-register-session tmux-maybe-create tmux-attach-or-switch ]; }