Skip to content

Commit 9f0cf65

Browse files
author
Dillon Lees
committed
feat: add kitty to the list of supported terminals for automatic start
1 parent 1531b37 commit 9f0cf65

File tree

3 files changed

+102
-31
lines changed

3 files changed

+102
-31
lines changed

docs/automatic_start.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ Next time the computer is started:
1616
Config options:
1717
- `set -g @continuum-boot-options 'fullscreen'` - terminal window
1818
will go fullscreen
19-
- `set -g @continuum-boot-options 'iterm'` - start `iTerm` instead
19+
- `set -g @continuum-boot-options 'iterm'` - start [iTerm](https://www.iterm2.com) instead
2020
of `Terminal.app`
2121
- `set -g @continuum-boot-options 'iterm,fullscreen'` - start `iTerm`
2222
in fullscreen
23+
- `set -g @continuum-boot-options 'kitty'` - start [kitty](https://sw.kovidgoyal.net/kitty) instead
24+
of `Terminal.app`
25+
- `set -g @continuum-boot-options 'kitty,fullscreen'` - start `kitty`
26+
in fullscreen
27+
28+
Note: The first time you reboot your machine and activate this feature you may be prompted about a script requiring
29+
access to a system program (i.e. - System Events). If this happens tmux will not start automatically and you will need
30+
to go to `System Preferences -> Security & Privacy -> Accessability` and add the script to the list of apps that are
31+
allowed to control your computer.
2332

2433
### Linux
2534

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env bash
22

3-
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44

55
source "$CURRENT_DIR/../helpers.sh"
66
source "$CURRENT_DIR/../variables.sh"
77

88
template() {
9-
local tmux_start_script="$1"
10-
local is_fullscreen="$2"
9+
local tmux_start_script="$1"
10+
local is_fullscreen="$2"
1111

12-
local fullscreen_tag=""
13-
if [ "$is_fullscreen" == "true" ]; then
14-
# newline and spacing so tag is aligned with other tags in template
15-
fullscreen_tag=$'\n <string>fullscreen</string>'
16-
fi
12+
local fullscreen_tag=""
13+
if [ "$is_fullscreen" == "true" ]; then
14+
# newline and spacing so tag is aligned with other tags in template
15+
fullscreen_tag=$'\n <string>fullscreen</string>'
16+
fi
1717

18-
local content
19-
read -r -d '' content <<-EOF
18+
local content
19+
read -r -d '' content <<- EOF
2020
<?xml version="1.0" encoding="UTF-8"?>
2121
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2222
<plist version="1.0">
@@ -32,35 +32,37 @@ template() {
3232
</dict>
3333
</plist>
3434
EOF
35-
echo "$content"
35+
echo "$content"
3636
}
3737

3838
get_iterm_or_teminal_option_value() {
39-
local options="$1"
40-
if [[ "$options" =~ "iterm" ]]; then
41-
echo "iterm"
42-
else
43-
# Terminal.app is the default console app
44-
echo "terminal"
45-
fi
39+
local options="$1"
40+
if [[ "$options" =~ "iterm" ]]; then
41+
echo "iterm"
42+
elif [[ "$options" =~ "kitty" ]]; then
43+
echo "kitty"
44+
else
45+
# Terminal.app is the default console app
46+
echo "terminal"
47+
fi
4648
}
4749

4850
get_fullscreen_option_value() {
49-
local options="$1"
50-
if [[ "$options" =~ "fullscreen" ]]; then
51-
echo "true"
52-
else
53-
echo "false"
54-
fi
51+
local options="$1"
52+
if [[ "$options" =~ "fullscreen" ]]; then
53+
echo "true"
54+
else
55+
echo "false"
56+
fi
5557
}
5658

5759
main() {
58-
local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")"
59-
local iterm_or_terminal_value="$(get_iterm_or_teminal_option_value "$options")"
60-
local fullscreen_option_value="$(get_fullscreen_option_value "$options")"
61-
local tmux_start_script_path="${CURRENT_DIR}/osx_${iterm_or_terminal_value}_start_tmux.sh"
60+
local options="$(get_tmux_option "$auto_start_config_option" "$auto_start_config_default")"
61+
local iterm_or_terminal_value="$(get_iterm_or_teminal_option_value "$options")"
62+
local fullscreen_option_value="$(get_fullscreen_option_value "$options")"
63+
local tmux_start_script_path="${CURRENT_DIR}/osx_${iterm_or_terminal_value}_start_tmux.sh"
6264

63-
local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")"
64-
echo "$launchd_plist_file_content" > "$osx_auto_start_file_path"
65+
local launchd_plist_file_content="$(template "$tmux_start_script_path" "$fullscreen_option_value")"
66+
echo "$launchd_plist_file_content" > "$osx_auto_start_file_path"
6567
}
6668
main
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# for "true full screen" call the script with "fullscreen" as the first argument
4+
TRUE_FULL_SCREEN="$1"
5+
6+
start_terminal_and_run_tmux() {
7+
osascript <<- EOF
8+
tell application "kitty"
9+
activate
10+
delay 5
11+
tell application "System Events" to tell process "kitty"
12+
set frontmost to true
13+
keystroke "tmux"
14+
key code 36
15+
end tell
16+
end tell
17+
EOF
18+
}
19+
20+
resize_window_to_full_screen() {
21+
osascript <<- EOF
22+
tell application "kitty"
23+
activate
24+
tell application "System Events"
25+
if (every window of process "kitty") is {} then
26+
keystroke "n" using command down
27+
end if
28+
29+
tell application "Finder"
30+
set desktopSize to bounds of window of desktop
31+
end tell
32+
33+
set position of front window of process "kitty" to {0, 0}
34+
set size of front window of process "kitty" to {item 3 of desktopSize, item 4 of desktopSize}
35+
end tell
36+
end tell
37+
EOF
38+
}
39+
40+
resize_to_true_full_screen() {
41+
osascript <<- EOF
42+
tell application "kitty"
43+
activate
44+
delay 1
45+
tell application "System Events" to tell process "kitty"
46+
keystroke "f" using {control down, command down}
47+
end tell
48+
end tell
49+
EOF
50+
}
51+
52+
main() {
53+
start_terminal_and_run_tmux
54+
if [ "$TRUE_FULL_SCREEN" == "fullscreen" ]; then
55+
resize_to_true_full_screen
56+
else
57+
resize_window_to_full_screen
58+
fi
59+
}
60+
main

0 commit comments

Comments
 (0)