From fce5274f816b81984fc2cf70b513f31e163310e1 Mon Sep 17 00:00:00 2001 From: Martin Chaine Date: Mon, 25 Jul 2016 12:22:32 +0200 Subject: [PATCH] Introduce iTerm2 support (split, tab, window) --- rc/core/iterm.kak | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rc/core/iterm.kak diff --git a/rc/core/iterm.kak b/rc/core/iterm.kak new file mode 100644 index 00000000..faf8592d --- /dev/null +++ b/rc/core/iterm.kak @@ -0,0 +1,75 @@ +# 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{ + if [ "$TERM_PROGRAM" = "iTerm.app" -a -z "$TMUX" ]; then + echo " + alias global new iterm-new-vertical + alias global focus iterm-focus + " + fi + } +} + +def -hidden -params 1.. iterm-new-split-impl %{ + %sh{ + direction="$1" + shift + if [ $# -gt 0 ]; then kakoune_params="-e '$@'"; fi + sh_cmd="kak -c ${kak_session} ${kakoune_params}" + osascript \ + -e "tell application \"iTerm\"" \ + -e " tell current session of current window" \ + -e " tell (split ${direction} with same profile)" \ + -e " select" \ + -e " write text \"${sh_cmd}\"" \ + -e " end tell" \ + -e " end tell" \ + -e "end tell" + } +} + +def iterm-new-vertical -params .. -command-completion -docstring "Create a new vertical pane in iTerm" %{ + iterm-new-split-impl 'vertically' %arg{@} +} + +def iterm-new-horizontal -params .. -command-completion -docstring "Create a new horizontal pane in iTerm" %{ + iterm-new-split-impl 'horizontally' %arg{@} +} + +def iterm-new-tab -params .. -command-completion -docstring "Create a new tab in iTerm" %{ + %sh{ + if [ $# -gt 0 ]; then kakoune_params="-e '$@'"; fi + sh_cmd="kak -c ${kak_session} ${kakoune_params}" + osascript \ + -e "tell application \"iTerm\"" \ + -e " tell current window" \ + -e " tell current session of (create tab with default profile)" \ + -e " write text \"${sh_cmd}\"" \ + -e " end tell" \ + -e " end tell" \ + -e "end tell" + } +} + +def iterm-new-window -params .. -command-completion -docstring "Create a new iTerm window" %{ + %sh{ + if [ $# -gt 0 ]; then kakoune_params="-e '$@'"; fi + sh_cmd="kak -c ${kak_session} ${kakoune_params}" + osascript \ + -e "tell application \"iTerm\"" \ + -e " set w to (create window with default profile)" \ + -e " tell current session of w" \ + -e " write text \"${sh_cmd}\"" \ + -e " end tell" \ + -e "end tell" + } +} + +def iterm-focus -params 0..1 -client-completion -docstring "Focus the given client in iTerm" %{ + # Should be possible using ${kak_client_env_ITERM_SESSION_ID}. + %sh{echo "echo -color Error 'Not implemented yet for iTerm'"} +}