Merge remote-tracking branch '2xsaiko/outgoing/newlines-for-iterm2'

This commit is contained in:
Maxime Coste 2022-11-21 08:51:21 +11:00
commit 760a45556c
2 changed files with 27 additions and 57 deletions

View File

@ -8,18 +8,14 @@ evaluate-commands %sh{
[ -z "${kak_opt_windowing_modules}" ] || [ "$TERM_PROGRAM" = "iTerm.app" ] || echo 'fail iTerm not detected' [ -z "${kak_opt_windowing_modules}" ] || [ "$TERM_PROGRAM" = "iTerm.app" ] || echo 'fail iTerm not detected'
} }
define-command -hidden -params 2.. iterm-terminal-split-impl %{ define-command -hidden -params 2.. iterm-terminal-impl %{
nop %sh{ nop %sh{
direction="$1" direction="$1"
shift shift
# join the arguments as one string for the shell execution (see x11.kak) # join the arguments as one string for the shell execution (see x11.kak)
args=$( args=$(
for i in "$@"; do for i in "$@"; do
if [ "$i" = '' ]; then printf "'%s' " "$(printf %s "$i" | sed "s|'|'\\\\''|g")"
printf "'' "
else
printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |"
fi
done done
) )
@ -34,12 +30,26 @@ define-command -hidden -params 2.. iterm-terminal-split-impl %{
esc_path=$(do_esc "$PATH") esc_path=$(do_esc "$PATH")
esc_tmp=$(do_esc "$TMPDIR") esc_tmp=$(do_esc "$TMPDIR")
cmd="env PATH='${esc_path}' TMPDIR='${esc_tmp}' $escaped" cmd="env PATH='${esc_path}' TMPDIR='${esc_tmp}' $escaped"
if [ "$direction" = 'tab' ]; then
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
elif [ "$direction" = 'window' ]; then
osascript \
-e "tell application \"iTerm\"" \
-e " create window with default profile command \"${cmd}\"" \
-e "end tell" >/dev/null
else
osascript \ osascript \
-e "tell application \"iTerm\"" \ -e "tell application \"iTerm\"" \
-e " tell current session of current window" \ -e " tell current session of current window" \
-e " tell (split ${direction} with same profile command \"${cmd}\") to select" \ -e " tell (split ${direction} with same profile command \"${cmd}\") to select" \
-e " end tell" \ -e " end tell" \
-e "end tell" >/dev/null -e "end tell" >/dev/null
fi
} }
} }
@ -48,7 +58,7 @@ iterm-terminal-vertical <program> [<arguments>]: create a new terminal as an ite
The current pane is split into two, left and right The current pane is split into two, left and right
The program passed as argument will be executed in the new terminal'\ The program passed as argument will be executed in the new terminal'\
%{ %{
iterm-terminal-split-impl 'vertically' %arg{@} iterm-terminal-impl 'vertically' %arg{@}
} }
complete-command iterm-terminal-vertical shell complete-command iterm-terminal-vertical shell
@ -57,7 +67,7 @@ iterm-terminal-horizontal <program> [<arguments>]: create a new terminal as an i
The current pane is split into two, top and bottom The current pane is split into two, top and bottom
The program passed as argument will be executed in the new terminal'\ The program passed as argument will be executed in the new terminal'\
%{ %{
iterm-terminal-split-impl 'horizontally' %arg{@} iterm-terminal-impl 'horizontally' %arg{@}
} }
complete-command iterm-terminal-horizontal shell complete-command iterm-terminal-horizontal shell
@ -65,26 +75,7 @@ define-command iterm-terminal-tab -params 1.. -docstring '
iterm-terminal-tab <program> [<arguments>]: create a new terminal as an iterm tab iterm-terminal-tab <program> [<arguments>]: create a new terminal as an iterm tab
The program passed as argument will be executed in the new terminal'\ The program passed as argument will be executed in the new terminal'\
%{ %{
nop %sh{ iterm-terminal-impl 'tab' %arg{@}
# see above
args=$(
for i in "$@"; do
if [ "$i" = '' ]; then
printf "'' "
else
printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |"
fi
done
)
escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g')
cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped"
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
}
} }
complete-command iterm-terminal-tab shell complete-command iterm-terminal-tab shell
@ -92,24 +83,7 @@ define-command iterm-terminal-window -params 1.. -docstring '
iterm-terminal-window <program> [<arguments>]: create a new terminal as an iterm window iterm-terminal-window <program> [<arguments>]: create a new terminal as an iterm window
The program passed as argument will be executed in the new terminal'\ The program passed as argument will be executed in the new terminal'\
%{ %{
nop %sh{ iterm-terminal-impl 'window' %arg{@}
# see above
args=$(
for i in "$@"; do
if [ "$i" = '' ]; then
printf "'' "
else
printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |"
fi
done
)
escaped=$(printf %s "$args" | sed -e 's|\\|\\\\|g; s|"|\\"|g')
cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' $escaped"
osascript \
-e "tell application \"iTerm\"" \
-e " create window with default profile command \"${cmd}\"" \
-e "end tell" >/dev/null
}
} }
complete-command iterm-terminal-window shell complete-command iterm-terminal-window shell

View File

@ -17,11 +17,7 @@ define-command screen-terminal-impl -hidden -params 3.. %{
# see x11.kak for what this achieves # see x11.kak for what this achieves
args=$( args=$(
for i in "$@"; do for i in "$@"; do
if [ "$i" = '' ]; then printf "'%s' " "$(printf %s "$i" | sed "s|'|'\\\\''|g")"
printf "'' "
else
printf %s "$i" | sed -e "s|'|'\\\\''|g; s|^|'|; s|$|' |"
fi
done done
) )
screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty" screen -X screen sh -c "${args} ; screen -X remove" < "/dev/$tty"