mirror of
https://github.com/tmux-plugins/tmux-continuum.git
synced 2025-09-06 17:07:03 +00:00
Enable easy 'tmux auto start' configuration
This commit is contained in:
28
scripts/handle_tmux_automatic_start.sh
Executable file
28
scripts/handle_tmux_automatic_start.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
source "$CURRENT_DIR/variables.sh"
|
||||
|
||||
is_tmux_automatic_start_enabled() {
|
||||
local auto_start_value="$(get_tmux_option "$auto_start_option" "$auto_start_default")"
|
||||
[ "$auto_start_value" == "on" ]
|
||||
}
|
||||
|
||||
is_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
main() {
|
||||
if is_tmux_automatic_start_enabled; then
|
||||
if is_osx; then
|
||||
$CURRENT_DIR/handle_tmux_automatic_start/osx_enable.sh
|
||||
fi
|
||||
else
|
||||
if is_osx; then
|
||||
$CURRENT_DIR/handle_tmux_automatic_start/osx_disable.sh
|
||||
fi
|
||||
fi
|
||||
}
|
||||
main
|
10
scripts/handle_tmux_automatic_start/osx_disable.sh
Executable file
10
scripts/handle_tmux_automatic_start/osx_disable.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/../variables.sh"
|
||||
|
||||
main() {
|
||||
rm "$osx_auto_start_file_path" > /dev/null 2>&1
|
||||
}
|
||||
main
|
33
scripts/handle_tmux_automatic_start/osx_enable.sh
Executable file
33
scripts/handle_tmux_automatic_start/osx_enable.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/../variables.sh"
|
||||
|
||||
template() {
|
||||
local tmux_start_script="$1"
|
||||
local content
|
||||
read -r -d '' content <<-EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>${osx_auto_start_file_name}</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>${tmux_start_script}</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
echo "$content"
|
||||
}
|
||||
|
||||
main() {
|
||||
local launchd_plist_file_content="$(template "$CURRENT_DIR/osx_terminal_start_tmux.sh")"
|
||||
echo "$launchd_plist_file_content" > "$osx_auto_start_file_path"
|
||||
}
|
||||
main
|
61
scripts/handle_tmux_automatic_start/osx_iterm_start_tmux.sh
Executable file
61
scripts/handle_tmux_automatic_start/osx_iterm_start_tmux.sh
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# for "true full screen" call the script with "fullscreen" 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" == "fullscreen" ]; then
|
||||
resize_to_true_full_screen
|
||||
else
|
||||
resize_window_to_full_screen
|
||||
fi
|
||||
}
|
||||
main
|
48
scripts/handle_tmux_automatic_start/osx_terminal_start_tmux.sh
Executable file
48
scripts/handle_tmux_automatic_start/osx_terminal_start_tmux.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# for "true full screen" call the script with "fullscreen" 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" == "fullscreen" ]; then
|
||||
resize_to_true_full_screen
|
||||
else
|
||||
resize_window_to_full_screen
|
||||
fi
|
||||
}
|
||||
main
|
@ -14,3 +14,10 @@ auto_restore_option="@resurrect-auto-restore"
|
||||
auto_restore_default="off"
|
||||
|
||||
auto_restore_halt_file="${HOME}/tmux_no_auto_restore"
|
||||
|
||||
# tmux auto start options
|
||||
auto_start_option="@resurrect-auto-tmux-start"
|
||||
auto_start_default="off"
|
||||
|
||||
osx_auto_start_file_name="Tmux.Start.plist"
|
||||
osx_auto_start_file_path="${HOME}/Library/LaunchAgents/${osx_auto_start_file_name}"
|
||||
|
Reference in New Issue
Block a user