From b0d0af9525251f77d31b1a11ff618c221cae490c Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 17 Feb 2015 16:20:50 +0100 Subject: [PATCH] OS X system startup scripts for terminal and iterm --- .../osx_iterm_start_tmux.sh | 61 +++++++++++++++++++ .../osx_terminal_start_tmux.sh | 48 +++++++++++++++ 2 files changed, 109 insertions(+) create mode 100755 system_startup_scripts/osx_iterm_start_tmux.sh create mode 100755 system_startup_scripts/osx_terminal_start_tmux.sh diff --git a/system_startup_scripts/osx_iterm_start_tmux.sh b/system_startup_scripts/osx_iterm_start_tmux.sh new file mode 100755 index 0000000..56bf719 --- /dev/null +++ b/system_startup_scripts/osx_iterm_start_tmux.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# for "true full screen" call the script with "true" as the first argument +TRUE_FULL_SCREEN="$1" + +start_iterm_and_run_tmux() { + osascript <<-EOF + tell application "iTerm" + activate + + # open iterm window + try + set _session to current session of current terminal + on error + set _term to (make new terminal) + tell _term + launch session "Tmux" + set _session to current session + end tell + end try + + # start tmux + tell _session + write text "tmux" + end tell + end tell + EOF +} + +resize_window_to_full_screen() { + osascript <<-EOF + tell application "iTerm" + set winID to id of window 1 + tell i term application "Finder" + set desktopSize to bounds of window of desktop + end tell + set bounds of window id winID to desktopSize + end tell + EOF +} + +resize_to_true_full_screen() { + osascript <<-EOF + tell application "iTerm" + delay 1 + tell i term application "System Events" + key code 36 using {command down} + end tell + end tell + EOF +} + +main() { + start_iterm_and_run_tmux + if [ "$TRUE_FULL_SCREEN" == "true" ]; then + resize_to_true_full_screen + else + resize_window_to_full_screen + fi +} +main diff --git a/system_startup_scripts/osx_terminal_start_tmux.sh b/system_startup_scripts/osx_terminal_start_tmux.sh new file mode 100755 index 0000000..ba9ab46 --- /dev/null +++ b/system_startup_scripts/osx_terminal_start_tmux.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# for "true full screen" call the script with "true" as the first argument +TRUE_FULL_SCREEN="$1" + +start_terminal_and_run_tmux() { + osascript <<-EOF + tell application "Terminal" + if not (exists window 1) then reopen + activate + set winID to id of window 1 + do script "tmux" in window id winID + end tell + EOF +} + +resize_window_to_full_screen() { + osascript <<-EOF + tell application "Terminal" + set winID to id of window 1 + tell application "Finder" + set desktopSize to bounds of window of desktop + end tell + set bounds of window id winID to desktopSize + end tell + EOF +} + +resize_to_true_full_screen() { + osascript <<-EOF + tell application "Terminal" + delay 1 + tell application "System Events" + keystroke "f" using {control down, command down} + end tell + end tell + EOF +} + +main() { + start_terminal_and_run_tmux + if [ "$TRUE_FULL_SCREEN" == "true" ]; then + resize_to_true_full_screen + else + resize_window_to_full_screen + fi +} +main