Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Last active July 28, 2026 19:51
Show Gist options
  • Select an option

  • Save marcheiligers/e0673963f539196d9898da327e944fc3 to your computer and use it in GitHub Desktop.

Select an option

Save marcheiligers/e0673963f539196d9898da327e944fc3 to your computer and use it in GitHub Desktop.
Set the title, color, and split an iTerm2 tab
#!/bin/bash
# Usage: ./workspace "Tab Title" R G B
# Example: ./workspace "My Project" 100 150 250
TITLE="${1:-Workspace}"
RED="${2:-100}"
GREEN="${3:-150}"
BLUE="${4:-250}"
DIR="$PWD"
# 1. Set the tab title
echo -ne "\033]1;${TITLE}\007"
# 2. Set the tab color
echo -ne "\033]6;1;bg;red;brightness;${RED}\a"
echo -ne "\033]6;1;bg;green;brightness;${GREEN}\a"
echo -ne "\033]6;1;bg;blue;brightness;${BLUE}\a"
# 3. Split the panes using AppleScript
osascript <<EOF
tell application "iTerm2"
tell current window
-- Split original session horizontally to create bottom_session
tell current session
set bottom_session to split horizontally with same profile
end tell
-- Split bottom_session vertically to create bottom_middle_session
tell bottom_session
set bottom_middle_session to split vertically with same profile
end tell
-- Split bottom_middle_session vertically to create bottom_right_session
tell bottom_middle_session
set bottom_right_session to split vertically with same profile
end tell
-- Set titles and move all three bottom panes to the starting directory
tell bottom_session
set name to "${TITLE}"
write text "cd '${DIR}' && clear"
end tell
tell bottom_middle_session
set name to "${TITLE}"
write text "cd '${DIR}' && clear"
end tell
tell bottom_right_session
set name to "${TITLE}"
write text "cd '${DIR}' && clear"
end tell
end tell
end tell
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment