Enable easy 'tmux auto start' configuration

parent b0d0af95
# Changelog
### master
- enable "tmux auto start" for OS X
### v2.0.0, 2015-02-15
- enable automatic environment restore when tmux is started
......
# tmux-resurrect-auto
Continuous saving of tmux environment. Automatic restore when tmux is started.
Features:
- continuous saving of tmux environment
- automatic tmux start when computer/server is on
- automatic restore when tmux is started
These features enable uninterrupted tmux usage. No matter the computer or server
restarts, if the machine is on, tmux will be there how you left it off the last
time it was used.
#### Continuous saving
After this plugin is installed, `tmux-resurrect` will save environment at the
interval of 15 minutes. All the saving happens in the background without the
impact to your workflow.
Tmux environment will be saved at the interval of 15 minutes. All the saving
happens in the background without the impact to your workflow.
This action starts automatically when the plugin is installed.
#### Automatic tmux start
Tmux is automatically started after the computer/server is turned on.
Put `set -g @resurrect-auto-tmux-start 'on'` in `tmux.conf` to enable this.
#### Automatic restore
Last saved environment is automatically restored when tmux server is started.
Last saved environment is automatically restored when tmux is started.
Put `set -g @resurrect-auto-restore 'on'` in `tmux.conf` to enable this.
Note: automatic restore happens **exclusively** on tmux server start. No other
......
......@@ -12,6 +12,10 @@ supported_tmux_version_ok() {
$CURRENT_DIR/scripts/check_tmux_version.sh "$SUPPORTED_VERSION"
}
handle_tmux_automatic_start() {
$CURRENT_DIR/scripts/handle_tmux_automatic_start.sh
}
add_resurrect_save_interpolation() {
local status_right_value="$(get_tmux_option "status-right" "")"
local new_value="${save_command_interpolation}${status_right_value}"
......@@ -31,6 +35,8 @@ start_auto_restore_in_background() {
main() {
if supported_tmux_version_ok; then
handle_tmux_automatic_start
# Don't start saving right after tmux is started.
# We wanna give user a chance to restore previous session.
set_last_save_timestamp
......
#!/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
#!/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
#!/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
#!/usr/bin/env bash
# for "true full screen" call the script with "true" as the first argument
# for "true full screen" call the script with "fullscreen" as the first argument
TRUE_FULL_SCREEN="$1"
start_iterm_and_run_tmux() {
......@@ -52,7 +52,7 @@ resize_to_true_full_screen() {
main() {
start_iterm_and_run_tmux
if [ "$TRUE_FULL_SCREEN" == "true" ]; then
if [ "$TRUE_FULL_SCREEN" == "fullscreen" ]; then
resize_to_true_full_screen
else
resize_window_to_full_screen
......
#!/usr/bin/env bash
# for "true full screen" call the script with "true" as the first argument
# for "true full screen" call the script with "fullscreen" as the first argument
TRUE_FULL_SCREEN="$1"
start_terminal_and_run_tmux() {
......@@ -39,7 +39,7 @@ resize_to_true_full_screen() {
main() {
start_terminal_and_run_tmux
if [ "$TRUE_FULL_SCREEN" == "true" ]; then
if [ "$TRUE_FULL_SCREEN" == "fullscreen" ]; then
resize_to_true_full_screen
else
resize_window_to_full_screen
......
......@@ -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}"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment