Last active
September 15, 2020 03:14
-
-
Save mgreenly/571dc5d4a37e12eb0f495d6de7ebfb1e to your computer and use it in GitHub Desktop.
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/sh | |
# $1 is session/window name | |
# $2 is command to run in that session | |
mk_tmux_session() { | |
if [ -z "$1" ]; then | |
echo 'usage: startdev NAME' | |
exit 1 | |
fi | |
if ! tmux has-session -t "$1" > /dev/null 2>&1; then | |
echo "starting: $1" | |
tmux new-session -d -s "$1" -d | |
tmux rename-window -t "$1" "$1" | |
if [ -z "$2" ]; then | |
tmux send-keys -t "$1" 'ls -lh' C-M | |
else | |
tmux send-keys -t "$1" "$2" C-M | |
fi | |
else | |
echo "skipping: $1" | |
fi | |
} | |
# my preference is to always have two windows pinned to the top | |
# | |
# * !home - a bash shell in my $HOME directory | |
# * !notes - a shell running vim that pre-opens my shared notes file | |
# | |
# The basic pattern is to change to a directory and spawn a session | |
(cd $HOME; mk_tmux_session '!home', 'ls -lh') | |
(cd $HOME; mk_tmux_session '!notes' "vim $DROPBOX_DIR/notes.txt") | |
# Then I open which ever source directories relate to my current work. | |
# It's not uncommon for me to have several of these listed. These are | |
# effectively equivalant to project tabs in an IDE | |
(cd $HOME/Projects/sample1; mk_tmux_session 'sample1' 'ls -lh') | |
(cd $HOME/Projects/sample2; mk_tmux_session 'sample2' 'ls -lh') | |
(cd $HOME/Projects/sample3; mk_tmux_session 'sample3' 'ls -lh') | |
cat <<- USAGE | |
Some useful TMux key bindings. | |
'C-a L' previous session | |
'C-a s' to choose session from list | |
Some useful TMux commands. | |
$> tmux kill-session -t NAME | |
$> tmux kill-server | |
USAGE | |
# finally if I'm not already attached to a tmux session start in home | |
[ -z "$TMUX" ] && tmux attach -t "!home" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment