dotfiles/.config/kak/autoload/sh.kak

48 lines
1.5 KiB
Text

define-command -docstring %{
shell-command [switches] <args>: Run the given shell command. Display
its output in an info modal.
Switches:
-d echo stdout to *debug* buffer as well
} -params 1.. shell-command %{
evaluate-commands %sh{
if [ "$1" = "-d" ]; then
debug="true"
shift
fi
stdout="$(eval "$@")"
printf 'info -title sh "%s"\n' "$stdout"
if [ "$debug" = "true" ]; then
printf 'echo -debug -- "%s"\n' "$stdout"
fi
}
}
define-command -docstring %{
shell-async-command [switches] <args>: Run the given shell command
asynchronously. Display its output in an info modal.
Switches:
-d echo stdout to *debug* buffer as well
} -params 1.. shell-async-command %{
nop %sh{
{
if [ "$1" = "-d" ]; then
debug="true"
shift
fi
stdout="$(eval "$@")"
cmd="$(printf 'info -title sh "%s"\n' "$stdout")"
if [ "$debug" = "true" ]; then
dcmd="$(printf 'echo -debug "%s"\n' "$stdout")"
cmd="$(printf '%s\n%s' "$cmd" "$dcmd")"
fi
printf 'evaluate-commands -try-client %s %%{ %s }' "$kak_client" "$cmd" | kak -p "$kak_session"
} >/dev/null 2>&1 </dev/null &
}
}
alias global sh shell-command
alias global sh& shell-async-command
alias global ! shell-command
alias global !& shell-async-command
complete-command shell-command shell
complete-command shell-async-command shell