Skip to content

Instantly share code, notes, and snippets.

@dhhdev
Created June 19, 2016 02:30
Show Gist options
  • Save dhhdev/e0685d57ecf63da4940748b1ace85340 to your computer and use it in GitHub Desktop.
Save dhhdev/e0685d57ecf63da4940748b1ace85340 to your computer and use it in GitHub Desktop.
Create a named session to tmux with three panes, or attach if already present
#!/bin/bash
#
# ~/.tools/tmux.sh
#
# Author: Daniel H. Hemmingsen <dhh@v5.dk>
# Usage: tmux.sh session-name /path/to/start/from"
#
# Could make a simple check, with groups or something.
# To see if the students should get write access or not.
# If no write access (i.e., readonly) would be enforced.
# Of course the script would have to be saved with at
# least 655 permissions, so the student couldn't just
# change the script.
if [[ $1 ]]; then
tmux attach -t $1 && exit 0
tmux new-session -s $1 -d
tmux rename-window '$1' -t $1
tmux split-window -h -t $1
tmux split-window -v -t $1
if [[ $2 ]]; then
tmux send-keys -t $1:0.0 'cd '$2'; clear' C-m
tmux send-keys -t $1:0.1 'cd '$2'; clear' C-m
tmux send-keys -t $1:0.2 'cd '$2'; clear' C-m
fi
tmux attach -t $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment