[PATCH v3 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 8a / 06abd72ed9ce17efc0263f86e3cf22cd0735de
1 Return-Path: <too@guru-group.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id A8130431FBF\r
6         for <notmuch@notmuchmail.org>; Sun, 29 Mar 2015 09:38:02 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.438\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
12         tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id O-gEmwEA-aLB for <notmuch@notmuchmail.org>;\r
16         Sun, 29 Mar 2015 09:37:59 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id CE23E431FAE\r
19         for <notmuch@notmuchmail.org>; Sun, 29 Mar 2015 09:37:58 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 8C7AB10009D; Sun, 29 Mar 2015 19:37:35 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash\r
25         '\' escape\r
26 Date: Sun, 29 Mar 2015 19:37:34 +0300\r
27 Message-Id: <1427647054-7773-1-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 2.0.0\r
29 Cc: tomi.ollila@iki.fi\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.13\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Sun, 29 Mar 2015 16:38:02 -0000\r
43 \r
44 Use the printf -v convention to give output variable as argument\r
45 to escape () function so no subshell needs to be executed for\r
46 escaping input. The '-v' option to escape () is just syntactic\r
47 sugar for better understanding.\r
48 \r
49 Also, backslash is now escaped with another backslash for emacs. This\r
50 ie especially important at the end of string.\r
51 \r
52 `echo` is no longer used to write escaped output -- it might interpret\r
53 the escapes itself.\r
54 ---\r
55 \r
56 This is first patch of the series to be continued -- next one would\r
57 already collide with Jani's work so it is left for the future...\r
58 \r
59  notmuch-emacs-mua | 11 ++++++-----\r
60  1 file changed, 6 insertions(+), 5 deletions(-)\r
61 \r
62 diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
63 index 13f67be..7971430 100755\r
64 --- a/notmuch-emacs-mua\r
65 +++ b/notmuch-emacs-mua\r
66 @@ -22,9 +22,12 @@\r
67  \r
68  set -eu\r
69  \r
70 +# escape: "expand" '\' as '\\' and '"' as '\"'\r
71 +# calling convention: escape -v var "$arg" (like in bash printf).\r
72  escape ()\r
73  {\r
74 -    echo "${1//\"/\\\"}"\r
75 +    local __escape_arg__=${3//\\/\\\\}\r
76 +    printf -v $2 '%s' "${__escape_arg__//\"/\\\"}"\r
77  }\r
78  \r
79  EMACS=${EMACS-emacs}\r
80 @@ -72,9 +75,7 @@ while getopts :s:c:b:i:h opt; do\r
81             ;;\r
82      esac\r
83  \r
84 -\r
85 -    OPTARG="${OPTARG-none}"\r
86 -    OPTARG="$(escape "${OPTARG}")"\r
87 +    escape -v OPTARG "${OPTARG-none}"\r
88  \r
89      case "${opt}" in\r
90         --help|h)\r
91 @@ -117,7 +118,7 @@ done\r
92  \r
93  # Positional parameters.\r
94  for arg; do\r
95 -    arg="$(escape "${arg}")"\r
96 +    escape -v arg "${arg}"\r
97      ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
98  done\r
99  \r
100 -- \r
101 2.1.0\r
102 \r