Add a nop command to avoid accidental shell output evaluation

This commit is contained in:
Maxime Coste 2013-01-03 18:52:07 +01:00
parent f84e46f805
commit 08fd946c07
4 changed files with 12 additions and 4 deletions

View File

@ -194,6 +194,12 @@ Commands are entered using +:+.
or *g*lobal scope. or *g*lobal scope.
* +c[ol]a[lias] <name> <colspec>+: define a color alias, so that name can be * +c[ol]a[lias] <name> <colspec>+: define a color alias, so that name can be
used instead of colspec in contexts where a color is needed. 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 String syntax
------------- -------------

View File

@ -674,6 +674,8 @@ void register_commands()
{ {
CommandManager& cm = CommandManager::instance(); CommandManager& cm = CommandManager::instance();
cm.register_commands({"nop"}, [](const CommandParameters&, Context&){});
PerArgumentCommandCompleter filename_completer({ complete_filename }); PerArgumentCommandCompleter filename_completer({ complete_filename });
cm.register_commands({ "e", "edit" }, edit<false>, filename_completer); cm.register_commands({ "e", "edit" }, edit<false>, filename_completer);
cm.register_commands({ "e!", "edit!" }, edit<true>, filename_completer); cm.register_commands({ "e!", "edit!" }, edit<true>, filename_completer);

View File

@ -9,10 +9,10 @@ def -shell-params -file-completion \
else else
( ${kak_opt_grepcmd} "${kak_selection}" >& ${output} ) >& /dev/null < /dev/null & ( ${kak_opt_grepcmd} "${kak_selection}" >& ${output} ) >& /dev/null < /dev/null &
fi fi
echo "try %{ db *grep* } catch %{ } echo "try %{ db *grep* } catch %{}
edit -fifo ${output} *grep* edit -fifo ${output} *grep*
setb filetype 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 %{ hook global WinSetOption filetype=grep %{

View File

@ -2,10 +2,10 @@ def -shell-params make %{ %sh{
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
mkfifo ${output} mkfifo ${output}
( make $@ >& ${output} ) >& /dev/null < /dev/null & ( make $@ >& ${output} ) >& /dev/null < /dev/null &
echo "try %{ db *make* } catch %{ } echo "try %{ db *make* } catch %{}
edit -fifo ${output} *make* edit -fifo ${output} *make*
setb filetype 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 %{ hook global WinSetOption filetype=make %{