From 6ba34f7c693b7649690b8f4a9ab6162696ba5e98 Mon Sep 17 00:00:00 2001 From: thek4n Date: Thu, 31 Oct 2024 23:36:46 +0300 Subject: [PATCH] tmux add example session file --- .gitignore | 3 ++- home/user/.tmux/example-background-job | 36 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 home/user/.tmux/example-background-job diff --git a/.gitignore b/.gitignore index 080af1a..9b800d5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +!home/user/.tmux/ssh +!home/user/.tmux/example-background-job \ No newline at end of file diff --git a/home/user/.tmux/example-background-job b/home/user/.tmux/example-background-job new file mode 100644 index 0000000..65372cd --- /dev/null +++ b/home/user/.tmux/example-background-job @@ -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 \ No newline at end of file