Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tmux POC - detach-client going wonky
#!/bin/bash
SESSION=tmuxtest
tmux_new_or_attach()
{
local session=$1
tmux has-session -t "$session" > /dev/null 2>&1
should_attach=$?
if [[ "$should_attach" == 0 ]] ; then
tmux attach-session -t "$session"
echo "attached"
else
tmux -f ~/.tmux.conf new-session -d -s "$session"
echo "new using $config"
fi
}
tmux_run_attach()
{
local session=$1
tmux attach-session -t "$session"
}
select_window()
{
local session=$1
tmux select-window -t "$session:0"
}
window0()
{
local session=$1
local win=0
local name="HTOP"
local htopCmd="htop"
echo "Creating window $win"
tmux rename-window -t "$session:${win}" "$name"
echo "Sending keys to window $win"
tmux send-keys -t "$session:${win}.0" "$htopCmd" C-m
}
window1()
{
local session=$1
local win=1
local name="ANOTHER-WIN"
echo "Creating window $win"
tmux new-window -n "$name"
echo "Sending keys to window $win"
tmux send-keys -t "$session:${win}.0" "ls -la" C-m
}
main()
{
tmux_new_or_attach $SESSION $CONFIG
window0 $SESSION
window1 $SESSION
select_window $SESSION
tmux_run_attach $SESSION
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.