tmux add example session file
This commit is contained in:
parent
ee275b24b6
commit
6ba34f7c69
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,3 +32,4 @@ home/user/.tmux/*
|
||||
!home/user/.tmux/dotfiles
|
||||
!home/user/.tmux/sandbox
|
||||
!home/user/.tmux/ssh
|
||||
!home/user/.tmux/example-background-job
|
||||
36
home/user/.tmux/example-background-job
Normal file
36
home/user/.tmux/example-background-job
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user