2016-07-25 12:22:32 +02:00
|
|
|
# https://www.iterm2.com
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
## The default behaviour for the `new` command is to open an vertical pane in
|
|
|
|
## an iTerm session if not in a tmux session.
|
|
|
|
hook global KakBegin .* %{
|
|
|
|
%sh{
|
2018-06-30 13:07:20 +02:00
|
|
|
if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ]; then
|
2016-07-25 12:22:32 +02:00
|
|
|
echo "
|
|
|
|
alias global new iterm-new-vertical
|
|
|
|
alias global focus iterm-focus
|
|
|
|
"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden -params 1.. iterm-new-split-impl %{
|
2016-07-25 12:22:32 +02:00
|
|
|
%sh{
|
|
|
|
direction="$1"
|
|
|
|
shift
|
2018-06-30 13:07:20 +02:00
|
|
|
if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi
|
|
|
|
cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' kak -c '${kak_session}' ${kakoune_params}"
|
2018-03-23 22:06:36 +01:00
|
|
|
osascript \
|
|
|
|
-e "tell application \"iTerm\"" \
|
|
|
|
-e " tell current session of current window" \
|
|
|
|
-e " tell (split ${direction} with same profile command \"${cmd}\") to select" \
|
|
|
|
-e " end tell" \
|
|
|
|
-e "end tell" >/dev/null
|
2016-07-25 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 13:17:46 +02:00
|
|
|
define-command iterm-new-vertical -params .. -command-completion -docstring "Split the current pane into two, top and bottom" %{
|
2016-07-25 12:22:32 +02:00
|
|
|
iterm-new-split-impl 'vertically' %arg{@}
|
|
|
|
}
|
|
|
|
|
2018-06-30 13:17:46 +02:00
|
|
|
define-command iterm-new-horizontal -params .. -command-completion -docstring "Split the current pane into two, left and right" %{
|
2016-07-25 12:22:32 +02:00
|
|
|
iterm-new-split-impl 'horizontally' %arg{@}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params .. -command-completion \
|
2016-10-11 09:03:41 +02:00
|
|
|
-docstring %{iterm-new-tab [<arguments>]: create a new tab
|
|
|
|
All optional arguments are forwarded to the new kak client} \
|
|
|
|
iterm-new-tab %{
|
2016-07-25 12:22:32 +02:00
|
|
|
%sh{
|
2018-06-30 13:07:20 +02:00
|
|
|
if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi
|
|
|
|
cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' kak -c '${kak_session}' ${kakoune_params}"
|
2018-03-23 22:06:36 +01:00
|
|
|
osascript \
|
|
|
|
-e "tell application \"iTerm\"" \
|
|
|
|
-e " tell current window" \
|
|
|
|
-e " create tab with default profile command \"${cmd}\"" \
|
|
|
|
-e " end tell" \
|
|
|
|
-e "end tell" >/dev/null
|
2016-07-25 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params .. -command-completion \
|
2016-10-11 09:03:41 +02:00
|
|
|
-docstring %{iterm-new-window [<arguments>]: create a new window
|
|
|
|
All optional arguments are forwarded to the new kak client} \
|
|
|
|
iterm-new-window %{
|
2016-07-25 12:22:32 +02:00
|
|
|
%sh{
|
2018-06-30 13:07:20 +02:00
|
|
|
if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi
|
|
|
|
cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' kak -c '${kak_session}' ${kakoune_params}"
|
2018-03-23 22:06:36 +01:00
|
|
|
osascript \
|
|
|
|
-e "tell application \"iTerm\"" \
|
|
|
|
-e " create window with default profile command \"${cmd}\"" \
|
|
|
|
-e "end tell" >/dev/null
|
2016-07-25 12:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -params ..1 -client-completion \
|
2016-10-11 09:03:41 +02:00
|
|
|
-docstring %{iterm-focus [<client>]: focus the given client
|
|
|
|
If no client is passed then the current one is used} \
|
2018-02-20 10:56:06 +01:00
|
|
|
iterm-focus %{ %sh{
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
printf %s\\n "evaluate-commands -client '$1' focus"
|
|
|
|
else
|
|
|
|
session="${kak_client_env_ITERM_SESSION_ID#*:}"
|
|
|
|
osascript \
|
|
|
|
-e "tell application \"iTerm\" to repeat with aWin in windows" \
|
|
|
|
-e " tell aWin to repeat with aTab in tabs" \
|
|
|
|
-e " tell aTab to repeat with aSession in sessions" \
|
|
|
|
-e " tell aSession" \
|
|
|
|
-e " if (unique id = \"${session}\") then" \
|
|
|
|
-e " select" \
|
|
|
|
-e " end if" \
|
|
|
|
-e " end tell" \
|
|
|
|
-e " end repeat" \
|
|
|
|
-e " end repeat" \
|
|
|
|
-e "end repeat"
|
|
|
|
fi
|
|
|
|
}
|
2016-07-25 12:22:32 +02:00
|
|
|
}
|