From a095e9383c2da1cb8d0b911738a6f03e6e7be760 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 18 Apr 2019 10:34:34 +0100 Subject: [PATCH] Escape * in vimdebug before passing to debug With `setopt nonomatch` unescaped `*` can be used in command arguments however when passing command arguments to `vimdebug` the `*` _should_ be escaped so that the debugger e.g. `gdb` will correctly invoke the program where `setopt nonomatch` does not apply. --- build/build.plugin.zsh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build/build.plugin.zsh b/build/build.plugin.zsh index 688d0b6..d45d3a2 100644 --- a/build/build.plugin.zsh +++ b/build/build.plugin.zsh @@ -8,7 +8,16 @@ alias build="build-dir --build" # command line arguments. if [ `uname` = Linux ]; then if [[ "`vim --version`" =~ "^VIM - Vi IMproved 8\.1.*$" ]]; then - function vimdebug() { vim "+packadd termdebug" "+TermdebugCommand $*" } + autoload -U regexp-replace + function vimdebug() { + # For each item in $* replace * and \* and then replace \ with \\ + local args=() + for arg in "$@"; do + regexp-replace arg '\*' '\\*' + args+=($arg) + done + vim "+packadd termdebug" "+TermdebugCommand $args" + } alias debug='vimdebug' elif which cgdb &> /dev/null; then alias debug='cgdb --args' @@ -165,11 +174,11 @@ EOF # Build then run a target residing in `~build/bin`. build-run() { local target=$1; shift 1 - eval build $target && ~build/bin/$target $* + eval build $target && ~build/bin/$target "$@" } # Build then debug a target residing in `~build/bin`. build-debug() { local target=$1; shift 1 - eval build $target && debug ~build/bin/$target $* + eval build $target && debug ~build/bin/$target "$@" }