From 08fd946c07e2a45fd2edbb28217d66b3991607ef Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 Jan 2013 18:52:07 +0100 Subject: [PATCH] Add a nop command to avoid accidental shell output evaluation --- README.asciidoc | 6 ++++++ src/commands.cc | 2 ++ src/rc/grep.kak | 4 ++-- src/rc/make.kak | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index c543c68c..6d7a5e90 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -194,6 +194,12 @@ Commands are entered using +:+. or *g*lobal scope. * +c[ol]a[lias] +: define a color alias, so that name can be used instead of colspec in contexts where a color is needed. + * +nop+: does nothing, but as with every other commands, arguments may be + evaluated. So nop can be used for example to execute a shell command + while being sure that it's output will not be interpreted by kak. + :%sh{ echo echo tchou } will echo tchou in kakoune, wherease + :nop %sh{ echo echo tchou } will not, but both will execute the + shell command. String syntax ------------- diff --git a/src/commands.cc b/src/commands.cc index 6f32be9f..98fca3a1 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -674,6 +674,8 @@ void register_commands() { CommandManager& cm = CommandManager::instance(); + cm.register_commands({"nop"}, [](const CommandParameters&, Context&){}); + PerArgumentCommandCompleter filename_completer({ complete_filename }); cm.register_commands({ "e", "edit" }, edit, filename_completer); cm.register_commands({ "e!", "edit!" }, edit, filename_completer); diff --git a/src/rc/grep.kak b/src/rc/grep.kak index c4337653..8dd152a3 100644 --- a/src/rc/grep.kak +++ b/src/rc/grep.kak @@ -9,10 +9,10 @@ def -shell-params -file-completion \ else ( ${kak_opt_grepcmd} "${kak_selection}" >& ${output} ) >& /dev/null < /dev/null & fi - echo "try %{ db *grep* } catch %{ } + echo "try %{ db *grep* } catch %{} edit -fifo ${output} *grep* setb filetype grep - hook buffer BufClose .* %{ %sh{ rm -r $(dirname ${output}) } }" + hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }" }} hook global WinSetOption filetype=grep %{ diff --git a/src/rc/make.kak b/src/rc/make.kak index 8bb8f3ce..796effb3 100644 --- a/src/rc/make.kak +++ b/src/rc/make.kak @@ -2,10 +2,10 @@ def -shell-params make %{ %sh{ output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo mkfifo ${output} ( make $@ >& ${output} ) >& /dev/null < /dev/null & - echo "try %{ db *make* } catch %{ } + echo "try %{ db *make* } catch %{} edit -fifo ${output} *make* setb filetype make - hook buffer BufClose .* %{ %sh{ rm -r $(dirname ${output}) } }" + hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }" }} hook global WinSetOption filetype=make %{