Only accept one parameter to 'terminal' commands

Also explicitly state that they're executed in a shell scope
This commit is contained in:
Olivier Perret 2018-12-03 19:35:35 +01:00
parent c8403624a7
commit 74d1dc756a
4 changed files with 40 additions and 43 deletions

View File

@ -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 <program> [<arguments>]: create a new terminal as a screen pane
define-command screen-terminal-vertical -params 1 -shell-completion -docstring '
screen-terminal-vertical <program>: 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 <program> [<arguments>]: create a new terminal as a screen pane
define-command screen-terminal-horizontal -params 1 -shell-completion -docstring '
screen-terminal-horizontal <program>: 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 <program> [<arguments>]: 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 <program>: 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)"

View File

@ -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 <program> [<arguments>]: create a new terminal as a tmux pane
define-command tmux-terminal-vertical -params 1 -shell-completion -docstring '
tmux-terminal-vertical <program>: 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 <program> [<arguments>]: create a new terminal as a tmux pane
define-command tmux-terminal-horizontal -params 1 -shell-completion -docstring '
tmux-terminal-horizontal <program>: 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 <program> [<arguments>]: 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 [<commands>]: 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 [<commands>]: 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 [<commands>]: 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 '

View File

@ -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 <program> [<arguments>]: 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 <program>: 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 [<commands>]: 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 '

View File

@ -14,12 +14,12 @@ hook -group kitty-hooks global KakBegin .* %sh{
fi
}
define-command kitty-terminal -params 1.. -shell-completion -docstring '
kitty-terminal <program> [<arguments>]: 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 <program>: 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 <program> [<arguments>]: 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 <program>: 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"
}
}