Ferry Huberts | 4 Apr 2012 18:15
Gravatar

[PATCH v2 1/1] syntax-highlight: when the file has no extension, assume text

From: Ferry Huberts <ferry.huberts@...>

There are 2 situations:
1- empty extension: assuming text is better than highlight
   producing no output because of a missing argument.
2- no extension at all: assuming text is better than setting
   the extension to the filename, which is what now happens.

Signed-off-by: Ferry Huberts <ferry.huberts@...>
---
 filters/syntax-highlighting.sh |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh
index 5fcc9c9..8b09180 100755
--- a/filters/syntax-highlighting.sh
+++ b/filters/syntax-highlighting.sh
 <at>  <at>  -39,6 +39,9  <at>  <at> 
 BASENAME="$1"
 EXTENSION="${BASENAME##*.}"

+[ "${BASENAME}" == "${EXTENSION}" ] && EXTENSION=txt
+[ -z "${EXTENSION}" ] && EXTENSION=txt
+
 # map Makefile and Makefile.* to .mk
 [ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk

--

-- 
1.7.7.6
(Continue reading)

Lukas Fleischer | 4 Apr 2012 18:58
Picon

Re: [PATCH v2 1/1] syntax-highlight: when the file has no extension, assume text

On Wed, Apr 04, 2012 at 06:15:02PM +0200, Ferry Huberts wrote:
> From: Ferry Huberts <ferry.huberts@...>
> 
> There are 2 situations:
> 1- empty extension: assuming text is better than highlight
>    producing no output because of a missing argument.
> 2- no extension at all: assuming text is better than setting
>    the extension to the filename, which is what now happens.
> 
> Signed-off-by: Ferry Huberts <ferry.huberts@...>
> ---
>  filters/syntax-highlighting.sh |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh
> index 5fcc9c9..8b09180 100755
> --- a/filters/syntax-highlighting.sh
> +++ b/filters/syntax-highlighting.sh
>  <at>  <at>  -39,6 +39,9  <at>  <at> 
>  BASENAME="$1"
>  EXTENSION="${BASENAME##*.}"
>  
> +[ "${BASENAME}" == "${EXTENSION}" ] && EXTENSION=txt

There is no "==" in POSIX shell/test(1). This should probably be a
single equal sign ("=").

> +[ -z "${EXTENSION}" ] && EXTENSION=txt
> +
>  # map Makefile and Makefile.* to .mk
(Continue reading)

Ferry Huberts | 4 Apr 2012 19:07
Gravatar

Re: [PATCH v2 1/1] syntax-highlight: when the file has no extension, assume text


On 04-04-12 18:58, Lukas Fleischer wrote:
> On Wed, Apr 04, 2012 at 06:15:02PM +0200, Ferry Huberts wrote:
>> From: Ferry Huberts<ferry.huberts@...>
>>
>> There are 2 situations:
>> 1- empty extension: assuming text is better than highlight
>>     producing no output because of a missing argument.
>> 2- no extension at all: assuming text is better than setting
>>     the extension to the filename, which is what now happens.
>>
>> Signed-off-by: Ferry Huberts<ferry.huberts@...>
>> ---
>>   filters/syntax-highlighting.sh |    3 +++
>>   1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh
>> index 5fcc9c9..8b09180 100755
>> --- a/filters/syntax-highlighting.sh
>> +++ b/filters/syntax-highlighting.sh
>>  <at>  <at>  -39,6 +39,9  <at>  <at> 
>>   BASENAME="$1"
>>   EXTENSION="${BASENAME##*.}"
>>
>> +[ "${BASENAME}" == "${EXTENSION}" ]&&  EXTENSION=txt
>
> There is no "==" in POSIX shell/test(1). This should probably be a
> single equal sign ("=").
>
>> +[ -z "${EXTENSION}" ]&&  EXTENSION=txt
(Continue reading)

Christian Franke | 5 Apr 2012 11:38
Favicon

Re: [PATCH v2 1/1] syntax-highlight: when the file has no extension, assume text

On 04/04/2012 07:07 PM, Ferry Huberts wrote:
> On 04-04-12 18:58, Lukas Fleischer wrote:
>> There is no "==" in POSIX shell/test(1). This should probably be a
>> single equal sign ("=").

> it appears there is, or (if there is not) the line above also doesn't
> work (that line has been in since 56522eb, 19-11-2009)

$ cat << EOF > test.sh
if [ "magic" == "\$1" ]; then
    echo "Argument is magic."
fi
EOF
$ /bin/dash test.sh
[: 3: magic: unexpected operator
$ /bin/dash test.sh magic
[: 3: magic: unexpected operator
$ sed -e 's/==/=/' -i test.sh
$ /bin/dash test.sh
$ /bin/dash test.sh magic
Argument is magic.
$ /bin/bash test.sh
$ /bin/bash test.sh magic
Argument is magic.

dash is a posix compatible shell. As most people use bash as their
shell, incompatibilies with posix shell often go unnoticed for a long
time. A script should however either specify /bin/bash as interpreter
or adhere to the shell language given in POSIX.

(Continue reading)

Ferry Huberts | 5 Apr 2012 12:04
Gravatar

Re: [PATCH v2 1/1] syntax-highlight: when the file has no extension, assume text


On 05-04-12 11:38, Christian Franke wrote:
> On 04/04/2012 07:07 PM, Ferry Huberts wrote:
>> On 04-04-12 18:58, Lukas Fleischer wrote:
>>> There is no "==" in POSIX shell/test(1). This should probably be a
>>> single equal sign ("=").
>
>> it appears there is, or (if there is not) the line above also doesn't
>> work (that line has been in since 56522eb, 19-11-2009)
>
> $ cat<<  EOF>  test.sh
> if [ "magic" == "\$1" ]; then
>      echo "Argument is magic."
> fi
> EOF
> $ /bin/dash test.sh
> [: 3: magic: unexpected operator
> $ /bin/dash test.sh magic
> [: 3: magic: unexpected operator
> $ sed -e 's/==/=/' -i test.sh
> $ /bin/dash test.sh
> $ /bin/dash test.sh magic
> Argument is magic.
> $ /bin/bash test.sh
> $ /bin/bash test.sh magic
> Argument is magic.
>
> dash is a posix compatible shell. As most people use bash as their
> shell, incompatibilies with posix shell often go unnoticed for a long
> time. A script should however either specify /bin/bash as interpreter
(Continue reading)


Gmane