dotfiles/home/user/.tmux/example-background-job
2025-11-19 12:41:33 +03:00

31 lines
524 B
Bash

#!/bin/sh
set -eu
readonly SESSION=example-background-job
readonly MAINW=1
if tmux has-session -t="${SESSION}" 2>/dev/null; then
tmux kill-session -t "${SESSION}"
fi
tmux new-session -s "${SESSION}" -d -n "${MAINW}"
tmux switch-client -t "${SESSION}"
temp_script="$(mktemp)"
readonly temp_script
cat > "${temp_script}" << EOF
#!/bin/sh
rm \$0
sleep 3
tmux send-keys -t "${SESSION}:${MAINW}.1" 'echo hello' Enter
sleep 3
tmux kill-session -t "${SESSION}"
EOF
chmod +x "${temp_script}"
setsid -f "${temp_script}"