{"thread":{"id":"45538","subject":"[PATCH] userdiff: add build-in pattern for shell","startedAt":"2017-03-29T16:54:00Z","lastAt":"2017-03-30T18:08:47Z","messageCount":6,"participants":["Ivan Tham","Junio C Hamano","Pickfire"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"315686","messageId":"20170329165331.17742-1-pickfire@riseup.net","threadId":"45538","inReplyTo":null,"subject":"[PATCH] userdiff: add build-in pattern for shell","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2017-03-29T16:53:31Z","receivedAt":"2017-03-29T16:54:00Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"Shell are widely used but comes with lots of different patterns. The\nbuild-in pattern aim for POSIX-compatible shells with some additions:\n\n- Notably ${g//re/s} and ${g#cut}\n- \"function\" from bash\n\nSigned-off-by: Ivan Tham <pickfire@riseup.net>\n---\n Documentation/gitattributes.txt |  2 ++\n t/t4034-diff-words.sh           |  1 +\n t/t4034/sh/expect               | 14 ++++++++++++++\n t/t4034/sh/post                 |  7 +++++++\n t/t4034/sh/pre                  |  7 +++++++\n userdiff.c                      |  5 +++++\n 6 files changed, 36 insertions(+)\n create mode 100644 t/t4034/sh/expect\n create mode 100644 t/t4034/sh/post\n create mode 100644 t/t4034/sh/pre\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex a53d093ca..1bad72df2 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -706,6 +706,8 @@ patterns are available:\n \n - `ruby` suitable for source code in the Ruby language.\n \n+- `sh` suitable for source code in POSIX-compatible shells.\n+\n - `tex` suitable for source code for LaTeX documents.\n \n \ndiff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh\nindex 912df9122..2eb662f89 100755\n--- a/t/t4034-diff-words.sh\n+++ b/t/t4034-diff-words.sh\n@@ -313,6 +313,7 @@ test_language_driver perl\n test_language_driver php\n test_language_driver python\n test_language_driver ruby\n+test_language_driver sh\n test_language_driver tex\n \n test_expect_success 'word-diff with diff.sbe' '\ndiff --git a/t/t4034/sh/expect b/t/t4034/sh/expect\nnew file mode 100644\nindex 000000000..e7b0a9ae3\n--- /dev/null\n+++ b/t/t4034/sh/expect\n@@ -0,0 +1,14 @@\n+<BOLD>diff --git a/pre b/post<RESET>\n+<BOLD>index 7bb0d15..df3845b 100644<RESET>\n+<BOLD>--- a/pre<RESET>\n+<BOLD>+++ b/post<RESET>\n+<CYAN>@@ -1,7 +1,7 @@<RESET>\n+echo <GREEN>\"<RESET>Hello world<RED>!<RESET>\n+<RED>bomb<RESET><GREEN>?\"<RESET>\n+<GREEN>fork<RESET>(){ <RED>bomb<RESET><GREEN>fork<RESET>|<RED>bomb<RESET><GREEN>fork<RESET>& }\n+<RED>; bomb<RESET>\n+<RED>a<RESET><GREEN>x<RESET>=<RED>1 a<RESET><GREEN>2 x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>+<RED>1<RESET><GREEN>2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a-1<RESET><GREEN>x-2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>*<RED>1<RESET><GREEN>2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>/<RED>1<RESET><GREEN>2<RESET>))\n+<RED>a<RESET><GREEN>x<RESET>=$(<RED>a<RESET><GREEN>x<RESET>) <RED>a<RESET><GREEN>x<RESET>=`<RED>a<RESET><GREEN>x<RESET>` <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>#<RED>a<RESET><GREEN>x<RESET>*} <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>%<RED>a<RESET><GREEN>x<RESET>*} <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>//<RED>a<RESET><GREEN>x<RESET>/<RED>a<RESET><GREEN>x<RESET>}\n+command <RED>-h -v<RESET><GREEN>--help=all -q<RESET> | xargs -- echo <GREEN>2<RESET>><RED>&1 &<RESET><GREEN>/dev/null<RESET>\n+[ <RED>$a -eq $b<RESET><GREEN>$x -ne $y<RESET> ]&&echo <RED>aa<RESET><GREEN>xx<RESET>||echo <RED>bb<RESET><GREEN>yy<RESET>\n+[ \"<RED>$a<RESET><GREEN>$x<RESET>\"!=<RED>1<RESET><GREEN>2<RESET> ] && echo <RED>a<RESET><GREEN>x<RESET> || echo <RED>b<RESET><GREEN>y<RESET>\ndiff --git a/t/t4034/sh/post b/t/t4034/sh/post\nnew file mode 100644\nindex 000000000..df3845b4f\n--- /dev/null\n+++ b/t/t4034/sh/post\n@@ -0,0 +1,7 @@\n+echo \"Hello world?\"\n+fork(){ fork|fork& }\n+x=2 x=$((x+2)) x=$((x-2)) x=$((x*2)) x=$((x/2))\n+x=$(x) x=`x` x=${x#x*} x=${x%x*} x=${x//x/x}\n+command --help=all -q | xargs -- echo 2>/dev/null\n+[ $x -ne $y ]&&echo xx||echo yy\n+[ \"$x\"!=2 ] && echo x || echo y\ndiff --git a/t/t4034/sh/pre b/t/t4034/sh/pre\nnew file mode 100644\nindex 000000000..7bb0d1562\n--- /dev/null\n+++ b/t/t4034/sh/pre\n@@ -0,0 +1,7 @@\n+echo Hello world!\n+bomb(){ bomb|bomb& }; bomb\n+a=1 a=$((a+1)) a=$((a-1)) a=$((a*1)) a=$((a/1))\n+a=$(a) a=`a` a=${a#a*} a=${a%a*} a=${a//a/a}\n+command -h -v | xargs -- echo >&1 &\n+[ $a -eq $b ]&&echo aa||echo bb\n+[ \"$a\"!=1 ] && echo a || echo b\ndiff --git a/userdiff.c b/userdiff.c\nindex 8b732e40b..8d5127fb6 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -148,6 +148,11 @@ PATTERNS(\"csharp\",\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?\"\n \t \"|[-+*/<>%&^|=!]=|--|\\\\+\\\\+|<<=?|>>=?|&&|\\\\|\\\\||::|->\"),\n+PATTERNS(\"sh\",\n+\t \"^[ \\t]*(function )?[A-Za-z_][A-Za-z_0-9]*[ \\t]*()[\\t]*\\\\{?$\",\n+\t /* -- */\n+\t \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--\" /* command/param */\n+\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n IPATTERN(\"css\",\n \t \"![:;][[:space:]]*$\\n\"\n \t \"^[_a-z0-9].*$\",\n-- \n2.12.2.609.gf7d0c115f\n\n"},{"id":"315690","messageId":"xmqqzig49e4j.fsf@gitster.mtv.corp.google.com","threadId":"45538","inReplyTo":"20170329165331.17742-1-pickfire@riseup.net","subject":"Re: [PATCH] userdiff: add build-in pattern for shell","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-29T17:39:08Z","receivedAt":"2017-03-29T17:39:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ivan Tham <pickfire@riseup.net> writes:\n\n> Shell are widely used but comes with lots of different patterns. The\n> build-in pattern aim for POSIX-compatible shells with some additions:\n>\n> - Notably ${g//re/s} and ${g#cut}\n> - \"function\" from bash\n>\n> Signed-off-by: Ivan Tham <pickfire@riseup.net>\n> ---\n>  Documentation/gitattributes.txt |  2 ++\n>  t/t4034-diff-words.sh           |  1 +\n>  t/t4034/sh/expect               | 14 ++++++++++++++\n>  t/t4034/sh/post                 |  7 +++++++\n>  t/t4034/sh/pre                  |  7 +++++++\n>  userdiff.c                      |  5 +++++\n>  6 files changed, 36 insertions(+)\n>  create mode 100644 t/t4034/sh/expect\n>  create mode 100644 t/t4034/sh/post\n>  create mode 100644 t/t4034/sh/pre\n>\n> diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\n> index a53d093ca..1bad72df2 100644\n> --- a/Documentation/gitattributes.txt\n> +++ b/Documentation/gitattributes.txt\n> @@ -706,6 +706,8 @@ patterns are available:\n>  \n>  - `ruby` suitable for source code in the Ruby language.\n>  \n> +- `sh` suitable for source code in POSIX-compatible shells.\n\nThe new test you added seems to show that this is not limited to\nPOSIX shells but also understands bashisms like ${x//x/x}.  Perhaps\ndrop \"POSIX-compatible\" from here.\n\n> diff --git a/userdiff.c b/userdiff.c\n> index 8b732e40b..8d5127fb6 100644\n> --- a/userdiff.c\n> +++ b/userdiff.c\n> @@ -148,6 +148,11 @@ PATTERNS(\"csharp\",\n>  \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n>  \t \"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?\"\n>  \t \"|[-+*/<>%&^|=!]=|--|\\\\+\\\\+|<<=?|>>=?|&&|\\\\|\\\\||::|->\"),\n> +PATTERNS(\"sh\",\n> +\t \"^[ \\t]*(function )?[A-Za-z_][A-Za-z_0-9]*[ \\t]*()[\\t]*\\\\{?$\",\n\nThere is something funky going on around parentheses on this line.\nThe ones around \"function \" is meant to be syntactic metacharacters\nto produce a group in the regexp so that you can apply '?'\n(i.e. zero or one occurrence) to it.  But I think the second pair of\nparentheses that appears later on the line, which enclose nothing,\nare meant to be literal?  E.g. \"hello (){\\n\\techo world;\\n}\\n\"  They\nwould need some quoting, perhaps like\n\n\t...[ \\t]*\\\\(\\\\)[\\t]*....\n\n> +\t /* -- */\n> +\t \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--\" /* command/param */\n\nTBH, I have no idea what this line-noise is doing.\n\n$foobar, $4, --foobar, foobar, 123 and -- can be seen easily out of\nthese patterns.  I am not sure what --# would be (perhaps you meant\nto only catch $# and --# is included by accident, in which case it\nis understandable).  It feels a bit strange to see that $# is\nsupported but not $?; --foo but not --foo=bar; foobar but not \"foo\nbar\" inside a dq-pair.\n\n> +\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n\nAnd this one is even more dense.\n"},{"id":"315734","messageId":"20170330022822.YGyP5YgSE%pickfire@riseup.net","threadId":"45538","inReplyTo":"xmqqzig49e4j.fsf@gitster.mtv.corp.google.com","subject":"Re: Re: [PATCH] userdiff: add build-in pattern for shell","fromName":"Pickfire","fromEmail":"pickfire@riseup.net","sentAt":"2017-03-30T02:28:22Z","receivedAt":"2017-03-30T02:28:43Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n\n> Ivan Tham <pickfire@riseup.net> writes:\n> \n> > Shell are widely used but comes with lots of different patterns. The\n> > build-in pattern aim for POSIX-compatible shells with some additions:\n> >\n> > - Notably ${g//re/s} and ${g#cut}\n> > - \"function\" from bash\n> >\n> > Signed-off-by: Ivan Tham <pickfire@riseup.net>\n> > ---\n> >  Documentation/gitattributes.txt |  2 ++\n> >  t/t4034-diff-words.sh           |  1 +\n> >  t/t4034/sh/expect               | 14 ++++++++++++++\n> >  t/t4034/sh/post                 |  7 +++++++\n> >  t/t4034/sh/pre                  |  7 +++++++\n> >  userdiff.c                      |  5 +++++\n> >  6 files changed, 36 insertions(+)\n> >  create mode 100644 t/t4034/sh/expect\n> >  create mode 100644 t/t4034/sh/post\n> >  create mode 100644 t/t4034/sh/pre\n> >\n> > diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\n> > index a53d093ca..1bad72df2 100644\n> > --- a/Documentation/gitattributes.txt\n> > +++ b/Documentation/gitattributes.txt\n> > @@ -706,6 +706,8 @@ patterns are available:\n> >  \n> >  - `ruby` suitable for source code in the Ruby language.\n> >  \n> > +- `sh` suitable for source code in POSIX-compatible shells.\n> \n> The new test you added seems to show that this is not limited to\n> POSIX shells but also understands bashisms like ${x//x/x}.  Perhaps\n> drop \"POSIX-compatible\" from here\n\nThose shells are still POSIX-compatible so I think it is true to put\nthat or otherwise, something like fish shell will break since it is\nas well a shell but the syntax is totally different.\n\n> > diff --git a/userdiff.c b/userdiff.c\n> > index 8b732e40b..8d5127fb6 100644\n> > --- a/userdiff.c\n> > +++ b/userdiff.c\n> > @@ -148,6 +148,11 @@ PATTERNS(\"csharp\",\n> >  \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n> >  \t \"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?\"\n> >  \t \"|[-+*/<>%&^|=!]=|--|\\\\+\\\\+|<<=?|>>=?|&&|\\\\|\\\\||::|->\"),\n> > +PATTERNS(\"sh\",\n> > +\t \"^[ \\t]*(function )?[A-Za-z_][A-Za-z_0-9]*[ \\t]*()[\\t]*\\\\{?$\",\n> \n> There is something funky going on around parentheses on this line.\n> The ones around \"function \" is meant to be syntactic metacharacters\n> to produce a group in the regexp so that you can apply '?'\n> (i.e. zero or one occurrence) to it.  But I think the second pair of\n> parentheses that appears later on the line, which enclose nothing,\n> are meant to be literal?  E.g. \"hello (){\\n\\techo world;\\n}\\n\"  They\n> would need some quoting, perhaps like\n> \n> \t...[ \\t]*\\\\(\\\\)[\\t]*....\n\nAh, I think I forgot to escape the quoting of ( and ). I will send in another\npatch for that.\n\n> > +\t /* -- */\n> > +\t \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--\" /* command/param */\n> \n> TBH, I have no idea what this line-noise is doing.\n\nThat breaks word into \"a\", \"$a\" and \"-a\" as well as \"$1\" and \"$#\". I tried\nsupporting $? by adding +|#|\\\\?)--\" but it doesn't seemed like it is working.\n\n> $foobar, $4, --foobar, foobar, 123 and -- can be seen easily out of\n> these patterns.  I am not sure what --# would be (perhaps you meant\n> to only catch $# and --# is included by accident, in which case it\n> is understandable).  It feels a bit strange to see that $# is\n> supported but not $?; --foo but not --foo=bar; foobar but not \"foo\n> bar\" inside a dq-pair.\n\nYes, getting --# will be very rare in shell. I think it is better to seperate\nthe --foo=bar into --foo and bar. I don't get what you man by the dq-pair.\n\n> > +\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n> \n> And this one is even more dense.\n\nYes, that takes care of the operators, special symbols and stuff.\n"},{"id":"315751","messageId":"xmqqefxf7038.fsf@gitster.mtv.corp.google.com","threadId":"45538","inReplyTo":"20170330022822.YGyP5YgSE%pickfire@riseup.net","subject":"Re: [PATCH] userdiff: add build-in pattern for shell","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-30T06:25:15Z","receivedAt":"2017-03-30T06:25:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pickfire <pickfire@riseup.net> writes:\n\n>> > +- `sh` suitable for source code in POSIX-compatible shells.\n>> \n>> The new test you added seems to show that this is not limited to\n>> POSIX shells but also understands bashisms like ${x//x/x}.  Perhaps\n>> drop \"POSIX-compatible\" from here\n>\n> Those shells are still POSIX-compatible so I think it is true to put\n> that or otherwise, something like fish shell will break since it is\n> as well a shell but the syntax is totally different.\n\nScripts with bash-isms are not necessarily usable by POSIX\ncompatible shells (think \"dash\") and this highlighter recognises\nbash specific enhancements (which by the way is a plus), so if you\nabsolutely want to say \"POSIX something\" in order to clarify that\ncsh and friends do not apply, say \"POSIX-like\".\n\n>> \t...[ \\t]*\\\\(\\\\)[\\t]*....\n>\n> Ah, I think I forgot to escape the quoting of ( and ). I will send in another\n> patch for that.\n\nOK.  Note that we usually avoid applying a patch whose brokenness\nwas noticed while review (which then necessitates a follow up patch\n\"oops, the previous was botched; here is a fix-up\").  The \"another\npatch\" needs to be a v2, i.e. pretending as if the version of the\npatch we are discussing never happened, not an incremental on top of\nthe patch we are discussing..\n\n>> > +\t /* -- */\n>> > +\t \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--\" /* command/param */\n>> \n>> TBH, I have no idea what this line-noise is doing.\n>\n> That breaks word into \"a\", \"$a\" and \"-a\" as well as \"$1\" and \"$#\". I tried\n> supporting $? by adding +|#|\\\\?)--\" but it doesn't seemed like it is working.\n\nThis ...\n\n>> $foobar, $4, --foobar, foobar, 123 and -- can be seen easily out of\n>> these patterns.  I am not sure what --# would be (perhaps you meant\n>> to only catch $# and --# is included by accident, in which case it\n>> is understandable).  It feels a bit strange to see that $# is\n>> supported but not $?; --foo but not --foo=bar; foobar but not \"foo\n>> bar\" inside a dq-pair.\n>\n> Yes, getting --# will be very rare in shell. I think it is better to seperate\n> the --foo=bar into --foo and bar. I don't get what you man by the dq-pair.\n\nThese design decisions (e.g. what you decided are the tokens to be\ntaken as a word---taking \"--foo\" and \"bar\" as separate things when\ngiven \"--foo=bar\" is a good example but with this regexp you are\nmaking many other design decisions) need to be explained in the log\nmessage.  A string inside a double-quote pair is taken as a single\nparameter to the shell, e.g.\n\n    cmd \"arg that is quoted inside double-quote pair\" $#\n\nIt is unclear what your regexp is doing to such an argument.\n\n>> > +\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n>> \n>> And this one is even more dense.\n\nFYI, this is also pointing out the need to explain what kind of\nthings you wanted to recognise as words; explaining in a reply\nmessage is a good first step, as the questioner may find the\nexplanation in your response still inadequate, in which case you\nhave a chance to refine it, but the ultimate goal is to put the\npolished explanation that would help people who later want to\nunderstand what you added to the codebase by describing what you\nwanted to do with the change in either in-code comment or commit log\nmessage when you send an updated patch.\n\nThanks.\n"},{"id":"315754","messageId":"20170330072038.GA17735@riseup.net","threadId":"45538","inReplyTo":"xmqqefxf7038.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] userdiff: add build-in pattern for shell","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2017-03-30T07:20:38Z","receivedAt":"2017-03-30T07:20:49Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"On Wed, Mar 29, 2017 at 11:25:15PM -0700, Junio C Hamano wrote:\n>Pickfire <pickfire@riseup.net> writes:\n>\n>>> > +- `sh` suitable for source code in POSIX-compatible shells.\n>>>\n>>> The new test you added seems to show that this is not limited to\n>>> POSIX shells but also understands bashisms like ${x//x/x}.  Perhaps\n>>> drop \"POSIX-compatible\" from here\n>>\n>> Those shells are still POSIX-compatible so I think it is true to put\n>> that or otherwise, something like fish shell will break since it is\n>> as well a shell but the syntax is totally different.\n\nOkay, I will change it from POSIX-compatible to POSIX-like.\n\n>Scripts with bash-isms are not necessarily usable by POSIX compatible\n>shells (think \"dash\") and this highlighter recognises bash specific\n>enhancements (which by the way is a plus), so if you absolutely want to\n>say \"POSIX something\" in order to clarify that csh and friends do not\n>apply, say \"POSIX-like\".\n>\n>>> \t...[ \\t]*\\\\(\\\\)[\\t]*....\n>>\n>> Ah, I think I forgot to escape the quoting of ( and ). I will send in\n>> another patch for that.\n>\n>OK.  Note that we usually avoid applying a patch whose brokenness was\n>noticed while review (which then necessitates a follow up patch \"oops,\n>the previous was botched; here is a fix-up\").  The \"another patch\"\n>needs to be a v2, i.e. pretending as if the version of the patch we are\n>discussing never happened, not an incremental on top of the patch we\n>are discussing..\n\nYes, I will put in a V2 which comes with \"[PATCH v2]\" in reply to this\nthread.\n\n>>> > +\t /* -- */ +\n>>> > \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#)|--\" /* command/param\n>>> > */\n>>>\n>>> TBH, I have no idea what this line-noise is doing.\n>>\n>> That breaks word into \"a\", \"$a\" and \"-a\" as well as \"$1\" and \"$#\". I\n>> tried supporting $? by adding +|#|\\\\?)--\" but it doesn't seemed like\n>> it is working.\n>\n>This ...\n\n???\n\n>>> $foobar, $4, --foobar, foobar, 123 and -- can be seen easily out of\n>>> these patterns.  I am not sure what --# would be (perhaps you meant\n>>> to only catch $# and --# is included by accident, in which case it\n>>> is understandable).  It feels a bit strange to see that $# is\n>>> supported but not $?; --foo but not --foo=bar; foobar but not \"foo\n>>> bar\" inside a dq-pair.\n>>\n>> Yes, getting --# will be very rare in shell. I think it is better to\n>> seperate the --foo=bar into --foo and bar. I don't get what you man\n>> by the dq-pair.\n>\n>These design decisions (e.g. what you decided are the tokens to be\n>taken as a word---taking \"--foo\" and \"bar\" as separate things when\n>given \"--foo=bar\" is a good example but with this regexp you are making\n>many other design decisions) need to be explained in the log message.\n>A string inside a double-quote pair is taken as a single parameter to\n>the shell, e.g.\n>\n>    cmd \"arg that is quoted inside double-quote pair\" $#\n>\n>It is unclear what your regexp is doing to such an argument.\n\nOkay, I will put that into the log. I still don't quite know what you\nwant to achieve with:\n\n    cmd \"arg that is quoted inside double-quote pair\" $#\n\nIf I am correct, you are probably talking about:\n\n    \"cmd \"arg that is quoted inside double-quote pair\" $#\"\n\nThat will be handled with other words together.\n\n>>> > +\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n>>>\n>>> And this one is even more dense.\n>\n>FYI, this is also pointing out the need to explain what kind of things\n>you wanted to recognise as words; explaining in a reply message is a\n>good first step, as the questioner may find the explanation in your\n>response still inadequate, in which case you have a chance to refine\n>it, but the ultimate goal is to put the polished explanation that would\n>help people who later want to understand what you added to the codebase\n>by describing what you wanted to do with the change in either in-code\n>comment or commit log message when you send an updated patch.\n\nAh, I can point it out here:\n\n\\\\$[({]           start of $( or ${\n[)}]              ends ^\n[-+*/=!]=?        operators\n[\\\\]&%#/|]{1,2}   pipes and stuff like ${a##a} or &&\n[<>]{1,3}         io redirections\n[ \\t]#.*          comments\n\nI hope that makes it clear and concise.\n\n-- \nDo what you like, like what you do.  -- Pickfire\n"},{"id":"315802","messageId":"20170330180829.27879-1-pickfire@riseup.net","threadId":"45538","inReplyTo":"20170329165331.17742-1-pickfire@riseup.net","subject":"[PATCH v2] userdiff: add build-in pattern for shell","fromName":"Ivan Tham","fromEmail":"pickfire@riseup.net","sentAt":"2017-03-30T18:08:29Z","receivedAt":"2017-03-30T18:08:47Z","isPatch":true,"sender":{"key":"pickfire@riseup.net","avatar":null},"body":"Shell are widely used but comes with lots of different patterns. The\nbuild-in pattern aim for POSIX-like shells with some additions:\n\n- Notably ${g//re/s} and ${g#cut}\n- Bashisms such as \"function\"\n\nSigned-off-by: Ivan Tham <pickfire@riseup.net>\n---\n Documentation/gitattributes.txt |  2 ++\n t/t4034-diff-words.sh           |  1 +\n t/t4034/sh/expect               | 14 ++++++++++++++\n t/t4034/sh/post                 |  7 +++++++\n t/t4034/sh/pre                  |  7 +++++++\n userdiff.c                      |  5 +++++\n 6 files changed, 36 insertions(+)\n create mode 100644 t/t4034/sh/expect\n create mode 100644 t/t4034/sh/post\n create mode 100644 t/t4034/sh/pre\n\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex a53d093ca..f8440119d 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -706,6 +706,8 @@ patterns are available:\n \n - `ruby` suitable for source code in the Ruby language.\n \n+- `sh` suitable for source code in POSIX-like shells.\n+\n - `tex` suitable for source code for LaTeX documents.\n \n \ndiff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh\nindex 912df9122..2eb662f89 100755\n--- a/t/t4034-diff-words.sh\n+++ b/t/t4034-diff-words.sh\n@@ -313,6 +313,7 @@ test_language_driver perl\n test_language_driver php\n test_language_driver python\n test_language_driver ruby\n+test_language_driver sh\n test_language_driver tex\n \n test_expect_success 'word-diff with diff.sbe' '\ndiff --git a/t/t4034/sh/expect b/t/t4034/sh/expect\nnew file mode 100644\nindex 000000000..e7b0a9ae3\n--- /dev/null\n+++ b/t/t4034/sh/expect\n@@ -0,0 +1,14 @@\n+<BOLD>diff --git a/pre b/post<RESET>\n+<BOLD>index 7bb0d15..df3845b 100644<RESET>\n+<BOLD>--- a/pre<RESET>\n+<BOLD>+++ b/post<RESET>\n+<CYAN>@@ -1,7 +1,7 @@<RESET>\n+echo <GREEN>\"<RESET>Hello world<RED>!<RESET>\n+<RED>bomb<RESET><GREEN>?\"<RESET>\n+<GREEN>fork<RESET>(){ <RED>bomb<RESET><GREEN>fork<RESET>|<RED>bomb<RESET><GREEN>fork<RESET>& }\n+<RED>; bomb<RESET>\n+<RED>a<RESET><GREEN>x<RESET>=<RED>1 a<RESET><GREEN>2 x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>+<RED>1<RESET><GREEN>2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a-1<RESET><GREEN>x-2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>*<RED>1<RESET><GREEN>2<RESET>)) <RED>a<RESET><GREEN>x<RESET>=$((<RED>a<RESET><GREEN>x<RESET>/<RED>1<RESET><GREEN>2<RESET>))\n+<RED>a<RESET><GREEN>x<RESET>=$(<RED>a<RESET><GREEN>x<RESET>) <RED>a<RESET><GREEN>x<RESET>=`<RED>a<RESET><GREEN>x<RESET>` <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>#<RED>a<RESET><GREEN>x<RESET>*} <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>%<RED>a<RESET><GREEN>x<RESET>*} <RED>a<RESET><GREEN>x<RESET>=${<RED>a<RESET><GREEN>x<RESET>//<RED>a<RESET><GREEN>x<RESET>/<RED>a<RESET><GREEN>x<RESET>}\n+command <RED>-h -v<RESET><GREEN>--help=all -q<RESET> | xargs -- echo <GREEN>2<RESET>><RED>&1 &<RESET><GREEN>/dev/null<RESET>\n+[ <RED>$a -eq $b<RESET><GREEN>$x -ne $y<RESET> ]&&echo <RED>aa<RESET><GREEN>xx<RESET>||echo <RED>bb<RESET><GREEN>yy<RESET>\n+[ \"<RED>$a<RESET><GREEN>$x<RESET>\"!=<RED>1<RESET><GREEN>2<RESET> ] && echo <RED>a<RESET><GREEN>x<RESET> || echo <RED>b<RESET><GREEN>y<RESET>\ndiff --git a/t/t4034/sh/post b/t/t4034/sh/post\nnew file mode 100644\nindex 000000000..df3845b4f\n--- /dev/null\n+++ b/t/t4034/sh/post\n@@ -0,0 +1,7 @@\n+echo \"Hello world?\"\n+fork(){ fork|fork& }\n+x=2 x=$((x+2)) x=$((x-2)) x=$((x*2)) x=$((x/2))\n+x=$(x) x=`x` x=${x#x*} x=${x%x*} x=${x//x/x}\n+command --help=all -q | xargs -- echo 2>/dev/null\n+[ $x -ne $y ]&&echo xx||echo yy\n+[ \"$x\"!=2 ] && echo x || echo y\ndiff --git a/t/t4034/sh/pre b/t/t4034/sh/pre\nnew file mode 100644\nindex 000000000..7bb0d1562\n--- /dev/null\n+++ b/t/t4034/sh/pre\n@@ -0,0 +1,7 @@\n+echo Hello world!\n+bomb(){ bomb|bomb& }; bomb\n+a=1 a=$((a+1)) a=$((a-1)) a=$((a*1)) a=$((a/1))\n+a=$(a) a=`a` a=${a#a*} a=${a%a*} a=${a//a/a}\n+command -h -v | xargs -- echo >&1 &\n+[ $a -eq $b ]&&echo aa||echo bb\n+[ \"$a\"!=1 ] && echo a || echo b\ndiff --git a/userdiff.c b/userdiff.c\nindex 8b732e40b..72ffd85f1 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -148,6 +148,11 @@ PATTERNS(\"csharp\",\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?\"\n \t \"|[-+*/<>%&^|=!]=|--|\\\\+\\\\+|<<=?|>>=?|&&|\\\\|\\\\||::|->\"),\n+PATTERNS(\"sh\",\n+\t \"^[ \\t]*(function )?[A-Za-z_][A-Za-z_0-9]*[ \\t]*\\\\(\\\\)[\\t]*\\\\{?$\",\n+\t /* -- */\n+\t \"(\\\\$|--?)?([a-zA-Z_][a-zA-Z0-9._]*|[0-9]+|#|\\\\?)|--\" /* command/param */\n+\t \"|\\\\$[({]|[)}]|[-+*/=!]=?|[\\\\]&%#/|]{1,2}|[<>]{1,3}|[ \\t]#.*\"),\n IPATTERN(\"css\",\n \t \"![:;][[:space:]]*$\\n\"\n \t \"^[_a-z0-9].*$\",\n-- \n2.12.2.609.gf7d0c115f\n\n"}]}