From 9b5b9743973d581a7ec5951932a09f068b837359 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 20 Feb 2018 20:56:06 +1100 Subject: [PATCH] iterm.kak: Implement focus support --- rc/extra/iterm.kak | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/rc/extra/iterm.kak b/rc/extra/iterm.kak index 3e4ca05e..fbfdd4f8 100644 --- a/rc/extra/iterm.kak +++ b/rc/extra/iterm.kak @@ -81,7 +81,23 @@ All optional arguments are forwarded to the new kak client} \ define-command -params ..1 -client-completion \ -docstring %{iterm-focus []: focus the given client If no client is passed then the current one is used} \ - iterm-focus %{ - # Should be possible using ${kak_client_env_ITERM_SESSION_ID}. - %sh{echo "echo -markup '{Error}Not implemented yet for iTerm'"} + 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 + } }