mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
38 lines
870 B
Nix
38 lines
870 B
Nix
{
|
|
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
|
|
'';
|
|
};
|
|
in
|
|
symlinkJoin {
|
|
name = "tmux-sessionizer";
|
|
paths = [
|
|
tmux-register-session
|
|
tmux-maybe-create
|
|
];
|
|
}
|