tmux add example session file

This commit is contained in:
thek4n 2024-10-31 23:36:46 +03:00
parent ee275b24b6
commit 6ba34f7c69
2 changed files with 38 additions and 1 deletions

3
.gitignore vendored
View File

@ -31,4 +31,5 @@ home/user/.config/tmux/local.conf
home/user/.tmux/*
!home/user/.tmux/dotfiles
!home/user/.tmux/sandbox
!home/user/.tmux/ssh
!home/user/.tmux/ssh
!home/user/.tmux/example-background-job

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eu
set -m # enable background jobs
readonly SESSION=example-background-job
readonly MAINW=1
if tmux has-session -t "${SESSION}" &>/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/bash
cleanup() {
rm \$0 # remove self after exit
}
trap cleanup EXIT ERR
sleep 3
tmux send-keys -t "${SESSION}:${MAINW}.1" 'echo hello' Enter
sleep 3
tmux kill-session -t "${SESSION}"
EOF
chmod +x "${temp_script}"
nohup "${temp_script}" >/dev/null & # run in background