From 9f0cf6581bb016e10bcbbd2d6b97f3d3d0c85877 Mon Sep 17 00:00:00 2001 From: Dillon Lees Date: Mon, 6 Jul 2020 02:00:50 -0400 Subject: [PATCH] feat: add kitty to the list of supported terminals for automatic start --- docs/automatic_start.md | 11 +++- .../handle_tmux_automatic_start/osx_enable.sh | 62 ++++++++++--------- .../osx_kitty_start_tmux.sh | 60 ++++++++++++++++++ 3 files changed, 102 insertions(+), 31 deletions(-) create mode 100755 scripts/handle_tmux_automatic_start/osx_kitty_start_tmux.sh diff --git a/docs/automatic_start.md b/docs/automatic_start.md index be80e95..4092e4f 100644 --- a/docs/automatic_start.md +++ b/docs/automatic_start.md @@ -16,10 +16,19 @@ Next time the computer is started: Config options: - `set -g @continuum-boot-options 'fullscreen'` - terminal window will go fullscreen -- `set -g @continuum-boot-options 'iterm'` - start `iTerm` instead +- `set -g @continuum-boot-options 'iterm'` - start [iTerm](https://www.iterm2.com) instead of `Terminal.app` - `set -g @continuum-boot-options 'iterm,fullscreen'` - start `iTerm` in fullscreen +- `set -g @continuum-boot-options 'kitty'` - start [kitty](https://sw.kovidgoyal.net/kitty) instead + of `Terminal.app` +- `set -g @continuum-boot-options 'kitty,fullscreen'` - start `kitty` + in fullscreen + +Note: The first time you reboot your machine and activate this feature you may be prompted about a script requiring +access to a system program (i.e. - System Events). If this happens tmux will not start automatically and you will need +to go to `System Preferences -> Security & Privacy -> Accessability` and add the script to the list of apps that are +allowed to control your computer. ### Linux diff --git a/scripts/handle_tmux_automatic_start/osx_enable.sh b/scripts/handle_tmux_automatic_start/osx_enable.sh index 7e3e274..9fddc81 100755 --- a/scripts/handle_tmux_automatic_start/osx_enable.sh +++ b/scripts/handle_tmux_automatic_start/osx_enable.sh @@ -1,22 +1,22 @@ #!/usr/bin/env bash -CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$CURRENT_DIR/../helpers.sh" source "$CURRENT_DIR/../variables.sh" template() { - local tmux_start_script="$1" - local is_fullscreen="$2" + local tmux_start_script="$1" + local is_fullscreen="$2" - local fullscreen_tag="" - if [ "$is_fullscreen" == "true" ]; then - # newline and spacing so tag is aligned with other tags in template - fullscreen_tag=$'\n fullscreen' - fi + local fullscreen_tag="" + if [ "$is_fullscreen" == "true" ]; then + # newline and spacing so tag is aligned with other tags in template + fullscreen_tag=$'\n fullscreen' + fi - local content - read -r -d '' content <<-EOF + local content + read -r -d '' content <<- EOF @@ -32,35 +32,37 @@ template() { EOF - echo "$content" + echo "$content" } get_iterm_or_teminal_option_value() { - local options="$1" - if [[ "$options" =~ "iterm" ]]; then - echo "iterm" - else - # Terminal.app is the default console app - echo "terminal" - fi + local options="$1" + if [[ "$options" =~ "iterm" ]]; then + echo "iterm" + elif [[ "$options" =~ "kitty" ]]; then + echo "kitty" + else + # Terminal.app is the default console app + echo "terminal" + fi } get_fullscreen_option_value() { - local options="$1" - if [[ "$options" =~ "fullscreen" ]]; then - echo "true" - else - echo "false" - fi + local options="$1" + if [[ "$options" =~ "fullscreen" ]]; then + echo "true" + else + echo "false" + fi } main() { - local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")" - local iterm_or_terminal_value="$(get_iterm_or_teminal_option_value "$options")" - local fullscreen_option_value="$(get_fullscreen_option_value "$options")" - local tmux_start_script_path="${CURRENT_DIR}/osx_${iterm_or_terminal_value}_start_tmux.sh" + local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")" + local iterm_or_terminal_value="$(get_iterm_or_teminal_option_value "$options")" + local fullscreen_option_value="$(get_fullscreen_option_value "$options")" + local tmux_start_script_path="${CURRENT_DIR}/osx_${iterm_or_terminal_value}_start_tmux.sh" - local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")" - echo "$launchd_plist_file_content" > "$osx_auto_start_file_path" + local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")" + echo "$launchd_plist_file_content" > "$osx_auto_start_file_path" } main diff --git a/scripts/handle_tmux_automatic_start/osx_kitty_start_tmux.sh b/scripts/handle_tmux_automatic_start/osx_kitty_start_tmux.sh new file mode 100755 index 0000000..b696707 --- /dev/null +++ b/scripts/handle_tmux_automatic_start/osx_kitty_start_tmux.sh @@ -0,0 +1,60 @@ +#!/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 "kitty" + activate + delay 5 + tell application "System Events" to tell process "kitty" + set frontmost to true + keystroke "tmux" + key code 36 + end tell + end tell + EOF +} + +resize_window_to_full_screen() { + osascript <<- EOF +tell application "kitty" + activate + tell application "System Events" + if (every window of process "kitty") is {} then + keystroke "n" using command down + end if + + tell application "Finder" + set desktopSize to bounds of window of desktop + end tell + + set position of front window of process "kitty" to {0, 0} + set size of front window of process "kitty" to {item 3 of desktopSize, item 4 of desktopSize} + end tell +end tell +EOF +} + +resize_to_true_full_screen() { + osascript <<- EOF + tell application "kitty" + activate + delay 1 + tell application "System Events" to tell process "kitty" + 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