我想tmux
在 Sway 启动时启动服务器。因此我创建了sway.conf
以下内容:
exec ~/.config/sway/scripts/start-up.sh
我在哪个脚本中启动 tmux:
#!/usr/bin/env bash
# shellcheck disable=SC1091,SC2034
# set -e
# set -u
LOG=~/.sway-startup.log
# Save stdout and stderr to file
exec 3>&1 4>&2 >"$LOG" 2>&1
# Start tmux and make terminal on workspace 1.
echo "Start tmux, let it recreate the workspaces with resurrect"
tmux start-server
echo "Server started."
sleep 3
tmux list-sessions || {
echo "ERROR: The exit-empty is not set to off, so the server directly exits!" >&2
}
# Create one session if not yet existing, detach from it.
tmux new-session -D -s Main-1
echo "Sessions are:"
tmux list-sessions || {
echo "ERROR: Sessions should now be available restored from tmux-ressurect???!" >&2
}
echo "-----------"
echo "Finished"
我tmux.conf
有set exit-empty false
这样的情况,如果“tmux start-server”上没有会话,tmux 就不会退出(奇怪的行为......)。
我真的不确定是否需要阻止脚本退出,因为启动脚本的start-up.sh
日志 报告如下:~/.sway-startup.log
swaymsg exec .../start-up.sh
Start tmux, let it recreate the workspaces with resurrect
Server started.
Astrovim: 1 windows (created Sat Nov 25 21:40:20 2023)
Main-1: 1 windows (created Sat Nov 25 21:40:20 2023)
Main-2: 1 windows (created Sat Nov 25 21:40:20 2023)
NixOS: 1 windows (created Sat Nov 25 21:40:20 2023)
duplicate session: Main-1 ### <<<<<<<<<<<<<<<- thats because resurrect created the above sessions automatically.
Sessions are:
Astrovim: 1 windows (created Sat Nov 25 21:40:20 2023)
Main-1: 1 windows (created Sat Nov 25 21:40:20 2023)
Main-2: 1 windows (created Sat Nov 25 21:40:20 2023)
NixOS: 1 windows (created Sat Nov 25 21:40:20 2023)
-----------
Finished
之后当我tmux a
据报道no sessions
。这太奇怪了,服务器运行时如我所见btop
(以我的用户名运行),但也使用tmux -S /run/user/1000/tmux-1000 a
指向套接字的报告no sessions
?
我真的很困惑,不知道发生了什么事?我该如何解决这个奇怪的问题?不知何故,这是重新开始时的权限问题swaymsg
。
答案1
在使用 homemanager 的 NixOS 中,此脚本运行时某些环境变量尚未获取start-up.sh
。缺少的是TMUX_TMPDIR
之后设置的变量。
我需要写出这个变量,以便能够通过执行以下操作在启动脚本中获取它home-manager
:
# We need this file to source in `~/.config/sway/scripts/start-up.sh`
# to be able to properly start tmux because these variables are not
# yet sourced.
xdg.configFile."tmux/.tmux-env".text = ''
TMUX_TMPDIR="${config.home.sessionVariables.TMUX_TMPDIR}"
'';
因此,当 sway 启动时,它将default
套接字写入/tmp/$USER-1000/default
等,而这并不是在设置 sessionVariables 之后 tmux 正在寻找的目录。