Files
aglab.dotfiles/bin/startb
T
AgxCOy 31c2797f44 修修startb
- 现在会自动清理临时服务了
- 能正常展开别名了(如~)
2026-03-24 19:08:46 +08:00

41 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# like `start /b` in Windows CMD.
# PATH 不完整问题:
# 根据 niri 启动方式的不同,niri 读到的环境变量可能也不一样。
# - tty 进终端再 niri-session 拉起来大概是最完整的。毕竟已经加载 .xxxrc 了嘛。
# - 而像我这样用 sddm 进的 niri,由于直接从 systemd 启动,中间也没有任何机会更新 PATH,相比就最麻烦了。
# 根据谷鸽 AI 的回答,我这种情况只能在 ~/.config/environment.d/ 里静态补上环境变量。
# 之前不懂的时候用的是如下的奇技淫巧:
# PATH=$(zsh -c -i 'echo $PATH')
# export PATH
# https://vescrity.github.io/post/systemd-desktop-suspend/
#systemd-run --user --scope --slice=YukiLauncher.slice --unit="$1-$$".scope /bin/sh -c '"$@"' _ "$@"
if [ $# -lt 1 ]; then
echo "Usage: daemon-run COMMAND [ARGS...]"
exit 1
fi
UNIT_NAME="${1##*/}-$(date +%s%N)"
ENV_ARGS=(
--setenv=PATH="$PATH"
--setenv=NVM_DIR="$NVM_DIR"
--setenv=NVM_BIN="$NVM_BIN"
)
systemd-run --user \
"${ENV_ARGS[@]}" \
--working-directory="$PWD" \
--slice=StartProcess.slice \
--unit="$UNIT_NAME" \
--collect \
-- /bin/sh -c 'exec "$@"' _ "$@"
if [ $? -eq 0 ]; then
echo "Logs : journalctl --user -u $UNIT_NAME -f"
echo "Note : '$UNIT_NAME' will auto-destruct on exit."
fi