aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Ollila <tomi.ollila@iki.fi>2015-03-29 19:37:34 +0300
committerDavid Bremner <david@tethera.net>2015-04-03 09:27:35 +0900
commit0fa9cf75e51957f775fd74a7ca266e7a8edd7941 (patch)
tree9122840aaa4f0ea05dba426138082939b34a8670
parent244f8739543dd2f6cde1188074fc4b32272e8446 (diff)
notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape
Use the printf -v convention to give output variable as argument to escape () function so no subshell needs to be executed for escaping input. The '-v' option to escape () is just syntactic sugar for better understanding. Also, backslash is now escaped with another backslash for emacs. This ie especially important at the end of string. `echo` is no longer used to write escaped output -- it might interpret the escapes itself.
-rwxr-xr-xnotmuch-emacs-mua11
1 files changed, 6 insertions, 5 deletions
diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua
index 13f67bee..79714305 100755
--- a/notmuch-emacs-mua
+++ b/notmuch-emacs-mua
@@ -22,9 +22,12 @@
set -eu
+# escape: "expand" '\' as '\\' and '"' as '\"'
+# calling convention: escape -v var "$arg" (like in bash printf).
escape ()
{
- echo "${1//\"/\\\"}"
+ local __escape_arg__=${3//\\/\\\\}
+ printf -v $2 '%s' "${__escape_arg__//\"/\\\"}"
}
EMACS=${EMACS-emacs}
@@ -72,9 +75,7 @@ while getopts :s:c:b:i:h opt; do
;;
esac
-
- OPTARG="${OPTARG-none}"
- OPTARG="$(escape "${OPTARG}")"
+ escape -v OPTARG "${OPTARG-none}"
case "${opt}" in
--help|h)
@@ -117,7 +118,7 @@ done
# Positional parameters.
for arg; do
- arg="$(escape "${arg}")"
+ escape -v arg "${arg}"
ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"
done