-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghostty-tab
More file actions
executable file
·63 lines (50 loc) · 1.34 KB
/
ghostty-tab
File metadata and controls
executable file
·63 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env zsh
set -o ERR_EXIT
set -o NO_UNSET
set -o PIPE_FAIL
zmodload zsh/zutil
typeset -a opt_w opt_i
zparseopts -D -E w:=opt_w i:=opt_i
#TODO Only the last value is captured. Multiple of the same option is not cumulative. Make it cumulative.
workdir="${HOME}"
if (( ${#opt_w} )); then
workdir="${opt_w[2]}"
fi
the_input=""
if (( ${#opt_i} )); then
typeset -a input_values
for ((i=2; i<=${#opt_i}; i+=2)); do
input_values+=("${opt_i[i]}")
done
the_input="${(F)input_values}"
unset input_values
fi
terminal_id=$(osascript - "$workdir" <<-'APPLESCRIPT'
on run argv
set workdir to item 1 of argv
tell application id "com.mitchellh.ghostty"
set cfg to new surface configuration
set initial working directory of cfg to workdir
if (count of windows) = 0 then
set theWindow to new window with configuration cfg
set theTab to selected tab of theWindow
else
set theTab to new tab in first window with configuration cfg
end if
return id of focused terminal of theTab
end tell
end run
APPLESCRIPT
)
if [[ -n "$the_input" ]]; then
sleep 0.1
osascript - "$terminal_id" "$the_input" <<-'APPLESCRIPT'
on run argv
set terminalId to item 1 of argv
set theInput to item 2 of argv
tell application id "com.mitchellh.ghostty"
input text theInput to terminal id terminalId
end tell
end run
APPLESCRIPT
fi