Bug 99473

Summary: Add shebang magic for gjs JavaScript files
Product: shared-mime-info Reporter: Philip Withnall <bugzilla>
Component: freedesktop.org.xmlAssignee: Shared Mime Info group <shared_mime_info>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: bugzilla
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Add application/x-executable as a supertype of application/ecmascript
Add shebang magic for gjs JavaScript files

Description Philip Withnall 2017-01-20 12:22:09 UTC
Patch to do that, plus another small cleanup, attached. Includes test cases.
Comment 1 Philip Withnall 2017-01-20 12:22:12 UTC
Created attachment 129065 [details] [review]
Add application/x-executable as a supertype of application/ecmascript

Just like Python.
Comment 2 Philip Withnall 2017-01-20 12:22:15 UTC
Created attachment 129066 [details] [review]
Add shebang magic for gjs JavaScript files

When writing scripts with gjs, it’s possible to write a program with no
`.js` suffix, but with a shebang line which invokes gjs. Add some magic
to detect that as application/x-javascript.
Comment 3 Bastien Nocera 2017-01-20 12:27:51 UTC
Comment on attachment 129066 [details] [review]
Add shebang magic for gjs JavaScript files

Review of attachment 129066 [details] [review]:
-----------------------------------------------------------------

::: freedesktop.org.xml.in
@@ +2391,5 @@
> +      <match type="string" value='eval \"exec /bin/gjs' offset="0"/>
> +      <match type="string" value="#!/usr/bin/gjs" offset="0"/>
> +      <match type="string" value="#! /usr/bin/gjs" offset="0"/>
> +      <match type="string" value='eval \"exec /usr/bin/gjs' offset="0"/>
> +      <match type="string" value="#!/usr/local/bin/gjs" offset="0"/>

Why /usr/local as well? Where would it apply?
Comment 4 Philip Withnall 2017-01-20 13:01:25 UTC
(In reply to Bastien Nocera from comment #3)
> Comment on attachment 129066 [details] [review] [review]
> Add shebang magic for gjs JavaScript files
> 
> Review of attachment 129066 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: freedesktop.org.xml.in
> @@ +2391,5 @@
> > +      <match type="string" value='eval \"exec /bin/gjs' offset="0"/>
> > +      <match type="string" value="#!/usr/bin/gjs" offset="0"/>
> > +      <match type="string" value="#! /usr/bin/gjs" offset="0"/>
> > +      <match type="string" value='eval \"exec /usr/bin/gjs' offset="0"/>
> > +      <match type="string" value="#!/usr/local/bin/gjs" offset="0"/>
> 
> Why /usr/local as well? Where would it apply?

I copied the magic matches from the Python rule (and changed `python` to `gjs`), since I think they’re fairly analogous.
Comment 5 Bastien Nocera 2017-01-20 13:47:54 UTC
Attachment 129065 [details] pushed as 8d771b2 - Add application/x-executable as a supertype of application/ecmascript
Attachment 129066 [details] pushed as c8d957d - Add shebang magic for gjs JavaScript files

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.