From 38c573415326211caac9ba9920165061eb69a43b Mon Sep 17 00:00:00 2001 From: foucault Date: Fri, 27 Dec 2024 17:49:42 -0500 Subject: [PATCH 1/3] add support for ghostty --- .../handle_tmux_automatic_start/osx_enable.sh | 74 ++++++++++--------- .../osx_ghostty_start_tmux.sh | 68 +++++++++++++++++ 2 files changed, 106 insertions(+), 36 deletions(-) create mode 100755 scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh diff --git a/scripts/handle_tmux_automatic_start/osx_enable.sh b/scripts/handle_tmux_automatic_start/osx_enable.sh index a7fea78..3fc60f3 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,41 +32,43 @@ template() { EOF - echo "$content" + echo "$content" } get_strategy() { - local options="$1" - if [[ "$options" =~ "iterm" ]]; then - echo "iterm" - elif [[ "$options" =~ "kitty" ]]; then - echo "kitty" - elif [[ "$options" =~ "alacritty" ]]; then - echo "alacritty" - 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" + elif [[ "$options" =~ "alacritty" ]]; then + echo "alacritty" + elif [[ "$options" =~ "ghostty" ]]; then + echo "ghostty" + 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 strategy="$(get_strategy "$options")" - local fullscreen_option_value="$(get_fullscreen_option_value "$options")" - local tmux_start_script_path="${CURRENT_DIR}/osx_${strategy}_start_tmux.sh" + local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")" + local strategy="$(get_strategy "$options")" + local fullscreen_option_value="$(get_fullscreen_option_value "$options")" + local tmux_start_script_path="${CURRENT_DIR}/osx_${strategy}_start_tmux.sh" - local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")" - if ! diff "$osx_auto_start_file_path" <(echo "$launchd_plist_file_content") &>/dev/null ; then - echo "$launchd_plist_file_content" > "$osx_auto_start_file_path" - fi + local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")" + if ! diff "$osx_auto_start_file_path" <(echo "$launchd_plist_file_content") &>/dev/null; then + echo "$launchd_plist_file_content" >"$osx_auto_start_file_path" + fi } main diff --git a/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh new file mode 100755 index 0000000..956fb2b --- /dev/null +++ b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh @@ -0,0 +1,68 @@ +#!/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 "ghostty" + activate + delay 0.5 + tell application "System Events" to tell process "ghostty" + set frontmost to true + keystroke "tmux" + key code 36 + end tell + end tell + EOF +} + +resize_window_to_full_screen() { + osascript <<-EOF + tell application "ghostty" + activate + tell application "System Events" + if (every window of process "ghostty") 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 "ghostty" to {0, 0} + set size of front window of process "alacritty" to {item 3 of desktopSize, item 4 of desktopSize} + end tell + end tell + EOF +} + +resize_to_true_full_screen() { + osascript <<-EOF + tell application "" + activate + delay 0.5 + tell application "System Events" to tell process "ghostty" + if front window exists then + tell front window + if value of attribute "AXFullScreen" then + set value of attribute "AXFullScreen" to false + else + set value of attribute "AXFullScreen" to true + end if + end tell + end if + 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 From fb1502138434daa902c287184c4bb6fa30ed4478 Mon Sep 17 00:00:00 2001 From: foucault Date: Sat, 28 Dec 2024 12:43:43 -0500 Subject: [PATCH 2/3] fix typo --- scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh index 956fb2b..e09c194 100755 --- a/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh +++ b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh @@ -31,7 +31,7 @@ resize_window_to_full_screen() { end tell set position of front window of process "ghostty" to {0, 0} - set size of front window of process "alacritty" to {item 3 of desktopSize, item 4 of desktopSize} + set size of front window of process "ghostty" to {item 3 of desktopSize, item 4 of desktopSize} end tell end tell EOF From 6921866b8c8945a0d76d9447aea82dd1569f48a0 Mon Sep 17 00:00:00 2001 From: foucault Date: Wed, 23 Apr 2025 15:37:36 -0400 Subject: [PATCH 3/3] fix an empty quote --- scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh index e09c194..9011859 100755 --- a/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh +++ b/scripts/handle_tmux_automatic_start/osx_ghostty_start_tmux.sh @@ -39,7 +39,7 @@ resize_window_to_full_screen() { resize_to_true_full_screen() { osascript <<-EOF - tell application "" + tell application "ghostty" activate delay 0.5 tell application "System Events" to tell process "ghostty"