From 3ae94d017dd5ff2a9c7f4e9f176d8062525b892d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 24 Mar 2018 08:06:36 +1100 Subject: [PATCH] iterm.kak: use command argument instead of sending text Instead of starting the default shell and sending it text (hoping it will support POSIX like shell syntax), just use the `env` utility to set the correct environment and exec kakoune. --- rc/extra/iterm.kak | 55 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/rc/extra/iterm.kak b/rc/extra/iterm.kak index fbfdd4f8..748c007f 100644 --- a/rc/extra/iterm.kak +++ b/rc/extra/iterm.kak @@ -18,18 +18,14 @@ define-command -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 \"export TMPDIR='${TMPDIR}'\"" \ - -e " write text \"exec ${sh_cmd}\"" \ - -e " end tell" \ - -e " end tell" \ - -e "end tell" + if [ $# -gt 0 ]; then kakoune_params="-e \\\"$@\\\""; fi + cmd="env -P ${PATH} TMPDIR=${TMPDIR} 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 command \"${cmd}\") to select" \ + -e " end tell" \ + -e "end tell" >/dev/null } } @@ -46,17 +42,14 @@ define-command -params .. -command-completion \ All optional arguments are forwarded to the new kak client} \ iterm-new-tab %{ %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 \"export TMPDIR='${TMPDIR}'\"" \ - -e " write text \"exec ${sh_cmd}\"" \ - -e " end tell" \ - -e " end tell" \ - -e "end tell" + if [ $# -gt 0 ]; then kakoune_params="-e \\\"$@\\\""; fi + cmd="env -P ${PATH} TMPDIR=${TMPDIR} kak -c ${kak_session} ${kakoune_params}" + 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 } } @@ -65,16 +58,12 @@ define-command -params .. -command-completion \ All optional arguments are forwarded to the new kak client} \ iterm-new-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-option w to (create window with default profile)" \ - -e " tell current session of w" \ - -e " write text \"export TMPDIR='${TMPDIR}'\"" \ - -e " write text \"exec ${sh_cmd}\"" \ - -e " end tell" \ - -e "end tell" + if [ $# -gt 0 ]; then kakoune_params="-e \\\"$@\\\""; fi + cmd="env -P ${PATH} TMPDIR=${TMPDIR} kak -c ${kak_session} ${kakoune_params}" + osascript \ + -e "tell application \"iTerm\"" \ + -e " create window with default profile command \"${cmd}\"" \ + -e "end tell" >/dev/null } }