appleterminal.kak (1625B)
1 # macOS Terminal.app 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 provide-module appleterminal %{ 5 6 # ensure that we're running in Terminal.app 7 evaluate-commands %sh{ 8 [ -z "${kak_opt_windowing_modules}" ] || [ "$TERM_PROGRAM" = "Apple_Terminal" ] || echo 'fail Terminal.app not detected' 9 } 10 11 define-command appleterminal-terminal-window -params 1.. -docstring ' 12 appleterminal-terminal-window <program> [<arguments>]: create a new terminal as a Terminal.app window 13 The program passed as argument will be executed in the new terminal'\ 14 %{ 15 nop %sh{ 16 # join the arguments as one string for the shell execution (see x11.kak) 17 quoted=$( 18 for i in exec env "PATH=$PATH" "TMPDIR=$TMPDIR" "$@"; do 19 printf "'%s' " "$(printf %s "$i" | sed "s|'|'\\\\''|g")" 20 done 21 ) 22 23 # since Terminal.app runs the command in the interactive shell, add initial space to prevent adding it to shell history 24 cmd=" $quoted" 25 echo "$cmd" | osascript \ 26 -e 'set s to (do shell script "cat 0<&3")' \ 27 -e 'tell application "Terminal" to do script s' >/dev/null 3<&0 28 } 29 } 30 complete-command appleterminal-terminal-window shell 31 32 alias global terminal appleterminal-terminal-window 33 34 define-command appleterminal-focus -params ..1 -docstring ' 35 appleterminal-focus [<client>]: focus the given client 36 If no client is passed then the current one is used' \ 37 %{ 38 fail 'Focusing Terminal.app client is unimplemented' 39 } 40 complete-command -menu appleterminal-focus client 41 42 alias global focus appleterminal-focus 43 44 }