From 74d1dc756ae9738877734aff562470e71c047a47 Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Mon, 3 Dec 2018 19:35:35 +0100 Subject: [PATCH] Only accept one parameter to 'terminal' commands Also explicitly state that they're executed in a shell scope --- rc/base/screen.kak | 24 +++++++++++------------- rc/base/tmux.kak | 33 ++++++++++++++++----------------- rc/base/x11.kak | 10 +++++----- rc/extra/kitty.kak | 16 ++++++++-------- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/rc/base/screen.kak b/rc/base/screen.kak index 4d13c375..5bf4292c 100644 --- a/rc/base/screen.kak +++ b/rc/base/screen.kak @@ -10,33 +10,31 @@ hook -group GNUscreen global KakBegin .* %sh{ " } -define-command screen-terminal-impl -hidden -params 3.. -command-completion %{ +define-command screen-terminal-impl -hidden -params 3 %{ nop %sh{ tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" screen -X eval "$1" "$2" - shift 2 - cmd=$(printf %s "$*") - screen -X screen sh -c "${cmd}; screen -X remove" < "/dev/$tty" + screen -X screen sh -c "$3; screen -X remove" < "/dev/$tty" } } -define-command screen-terminal-vertical -params 1.. -command-completion -docstring ' -screen-terminal-vertical []: create a new terminal as a screen pane +define-command screen-terminal-vertical -params 1 -shell-completion -docstring ' +screen-terminal-vertical : create a new terminal as a screen pane The current pane is split into two, left and right -The program passed as argument will be executed in the new terminal' \ +The shell program passed as argument will be executed in the new terminal' \ %{ screen-terminal-impl 'split -v' 'focus right' %arg{@} } -define-command screen-terminal-horizontal -params 1.. -command-completion -docstring ' -screen-terminal-horizontal []: create a new terminal as a screen pane +define-command screen-terminal-horizontal -params 1 -shell-completion -docstring ' +screen-terminal-horizontal : create a new terminal as a screen pane The current pane is split into two, top and bottom -The program passed as argument will be executed in the new terminal' \ +The shell program passed as argument will be executed in the new terminal' \ %{ screen-terminal-impl 'split -h' 'focus down' %arg{@} } -define-command screen-terminal-window -params 1.. -command-completion -docstring ' -screen-terminal-window []: create a new terminal as a screen window -The program passed as argument will be executed in the new terminal' \ +define-command screen-terminal-window -params 1 -shell-completion -docstring ' +screen-terminal-window : create a new terminal as a screen window +The shell program passed as argument will be executed in the new terminal' \ %{ nop %sh{ tty="$(ps -o tty ${kak_client_pid} | tail -n 1)" diff --git a/rc/base/tmux.kak b/rc/base/tmux.kak index c587cdb9..b1d6beb5 100644 --- a/rc/base/tmux.kak +++ b/rc/base/tmux.kak @@ -12,7 +12,7 @@ hook global KakBegin .* %sh{ fi } -define-command -hidden -params 2.. tmux-terminal-impl %{ +define-command -hidden -params 2 tmux-terminal-impl %{ evaluate-commands %sh{ tmux=${kak_client_env_TMUX:-$TMUX} if [ -z "$tmux" ]; then @@ -20,30 +20,29 @@ define-command -hidden -params 2.. tmux-terminal-impl %{ exit fi tmux_args="$1" - shift - TMUX=$tmux tmux $tmux_args env TMPDIR="$TMPDIR" sh -c "$*" < /dev/null > /dev/null 2>&1 & + TMUX=$tmux tmux $tmux_args env TMPDIR="$TMPDIR" sh -c "$2" < /dev/null > /dev/null 2>&1 & } } -define-command tmux-terminal-vertical -params 1.. -shell-completion -docstring ' -tmux-terminal-vertical []: create a new terminal as a tmux pane +define-command tmux-terminal-vertical -params 1 -shell-completion -docstring ' +tmux-terminal-vertical : create a new terminal as a tmux pane The current pane is split into two, top and bottom -The program passed as argument will be executed in the new terminal' \ +The shell program passed as argument will be executed in the new terminal' \ %{ - tmux-terminal-impl 'split-window -v' %arg{@} + tmux-terminal-impl 'split-window -v' %arg{1} } -define-command tmux-terminal-horizontal -params 1.. -shell-completion -docstring ' -tmux-terminal-horizontal []: create a new terminal as a tmux pane +define-command tmux-terminal-horizontal -params 1 -shell-completion -docstring ' +tmux-terminal-horizontal : create a new terminal as a tmux pane The current pane is split into two, left and right -The program passed as argument will be executed in the new terminal' \ +The shell program passed as argument will be executed in the new terminal' \ %{ - tmux-terminal-impl 'split-window -h' %arg{@} + tmux-terminal-impl 'split-window -h' %arg{1} } -define-command tmux-terminal-window -params 1.. -shell-completion -docstring ' +define-command tmux-terminal-window -params 1 -shell-completion -docstring ' tmux-terminal-window []: create a new terminal as a tmux window -The program passed as argument will be executed in the new terminal' \ +The shell program passed as argument will be executed in the new terminal' \ %{ - tmux-terminal-impl 'new-window' %arg{@} + tmux-terminal-impl 'new-window' %arg{1} } define-command tmux-new-vertical -params .. -command-completion -docstring ' @@ -51,20 +50,20 @@ tmux-new-vertical []: create a new kakoune client as a tmux pane The current pane is split into two, top and bottom The optional arguments are passed as commands to the new client' \ %{ - tmux-terminal-vertical "kak -c %val{session} -e '%arg{@}'" + tmux-terminal-vertical "kak -c '%val{session}' -e '%arg{@}'" } define-command tmux-new-horizontal -params .. -command-completion -docstring ' tmux-new-horizontal []: create a new kakoune client as a tmux pane The current pane is split into two, left and right The optional arguments are passed as commands to the new client' \ %{ - tmux-terminal-horizontal "kak -c %val{session} -e '%arg{@}'" + tmux-terminal-horizontal "kak -c '%val{session}' -e '%arg{@}'" } define-command tmux-new-window -params .. -command-completion -docstring ' tmux-new-window []: create a new kakoune client as a tmux window The optional arguments are passed as commands to the new client' \ %{ - tmux-terminal-window "kak -c %val{session} -e '%arg{@}'" + tmux-terminal-window "kak -c '%val{session}' -e '%arg{@}'" } define-command tmux-focus -params ..1 -client-completion -docstring ' diff --git a/rc/base/x11.kak b/rc/base/x11.kak index 9d5ee82e..c6f298d8 100644 --- a/rc/base/x11.kak +++ b/rc/base/x11.kak @@ -22,16 +22,16 @@ A shell command is appended to the one set in this option at runtime} \ done } -define-command x11-terminal -params 1.. -shell-completion -docstring ' -x11-terminal []: create a new terminal as an x11 window -The program passed as argument will be executed in the new terminal' \ +define-command x11-terminal -params 1 -shell-completion -docstring ' +x11-terminal : create a new terminal as an x11 window +The shell program passed as argument will be executed in the new terminal' \ %{ evaluate-commands %sh{ if [ -z "${kak_opt_termcmd}" ]; then echo "fail 'termcmd option is not set'" exit fi - setsid ${kak_opt_termcmd} "$*" < /dev/null > /dev/null 2>&1 & + setsid ${kak_opt_termcmd} "$1" < /dev/null > /dev/null 2>&1 & } } @@ -39,7 +39,7 @@ define-command x11-new -params .. -command-completion -docstring ' x11-new []: create a new kakoune client as an x11 window The optional arguments are passed as commands to the new client' \ %{ - x11-terminal "kak -c %val{session} -e '%arg{@}'" + x11-terminal "kak -c '%val{session}' -e '%arg{@}'" } define-command x11-focus -params ..1 -client-completion -docstring ' diff --git a/rc/extra/kitty.kak b/rc/extra/kitty.kak index c8533312..5f0bb24c 100644 --- a/rc/extra/kitty.kak +++ b/rc/extra/kitty.kak @@ -14,12 +14,12 @@ hook -group kitty-hooks global KakBegin .* %sh{ fi } -define-command kitty-terminal -params 1.. -shell-completion -docstring ' -kitty-terminal []: create a new terminal as a kitty window -The program passed as argument will be executed in the new terminal' \ +define-command kitty-terminal -params 1 -shell-completion -docstring ' +kitty-terminal : create a new terminal as a kitty window +The shell program passed as argument will be executed in the new terminal' \ %{ nop %sh{ - kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type sh -c "$*" + kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type sh -c "$1" } } @@ -30,12 +30,12 @@ The optional arguments are passed as commands to the new client' \ kitty-terminal "kak -c %val{session} -e '%arg{@}'" } -define-command kitty-terminal-tab -params 1.. -shell-completion -docstring ' -kitty-terminal-tab []: create a new terminal as kitty tab -The program passed as argument will be executed in the new terminal' \ +define-command kitty-terminal-tab -params 1 -shell-completion -docstring ' +kitty-terminal-tab : create a new terminal as kitty tab +The shell program passed as argument will be executed in the new terminal' \ %{ nop %sh{ - kitty @ new-window --no-response --new-tab sh -c "$*" + kitty @ new-window --no-response --new-tab sh -c "$1" } }