Skip to content

Instantly share code, notes, and snippets.

@dhulihan
Created March 18, 2019 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhulihan/2bc3fe3211f89e4726f0e3485e4f6c92 to your computer and use it in GitHub Desktop.
Save dhulihan/2bc3fe3211f89e4726f0e3485e4f6c92 to your computer and use it in GitHub Desktop.
tmux + iterm2 Create or Resume Session based on project dir
#!/bin/bash
# tmux-session
#
# Author: Dave Hulihan
# Description: Create/attach tmux session based on project directory. Works in bash, zsh.
#
function tmux-session {
SESSION_NAME=$(basename $PWD)
# set iterm2 title
iterm-tab-title $SESSION_NAME
# set iterm2 color
iterm-tab-color green
# attempt to attach to
tmux a -t $SESSION_NAME
if [[ $? -ne 0 ]] ; then
tmux new -s $SESSION_NAME -d
# create windows (one for git, one for your editor, one for builds/runtime)
DEFAULT_EDITOR=vim
EDITOR=${EDITOR:-$DEFAULT_EDITOR}
tmux new-window -t $SESSION_NAME -n $EDITOR
tmux new-window -t $SESSION_NAME -n zsh
# open vim on second window
tmux send-keys -t $SESSION_NAME:2 "$EDITOR" C-m
tmux select-window -t $SESSION_NAME:2
tmux a -t $SESSION_NAME
fi
}
function iterm-tab-title {
echo -ne "\033]0;"$1"\007"
}
function iterm-tab-color {
case $1 in
green)
echo -e "\033]6;1;bg;red;brightness;0\a"
echo -e "\033]6;1;bg;green;brightness;128\a"
echo -e "\033]6;1;bg;blue;brightness;0\a"
;;
red)
echo -e "\033]6;1;bg;red;brightness;270\a"
echo -e "\033]6;1;bg;green;brightness;60\a"
echo -e "\033]6;1;bg;blue;brightness;83\a"
;;
orange)
echo -e "\033]6;1;bg;red;brightness;227\a"
echo -e "\033]6;1;bg;green;brightness;143\a"
echo -e "\033]6;1;bg;blue;brightness;10\a"
;;
blue)
echo -e "\033]6;1;bg;red;brightness;16\a"
echo -e "\033]6;1;bg;green;brightness;221\a"
echo -e "\033]6;1;bg;blue;brightness;255\a"
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment