Created
May 9, 2016 16:29
-
-
Save beeryardtech/7163c1570fbe3ebc86fb361bff914948 to your computer and use it in GitHub Desktop.
Tmux POC - detach-client going wonky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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