After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 733624 - Apply shell syntax highlighting for ~/.bashrc etc
Apply shell syntax highlighting for ~/.bashrc etc
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: Syntax files
3.12.x
Other Linux
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-23 18:23 UTC by Magdalen Berns (irc magpie)
Modified: 2014-08-13 23:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add *bashrc *profile and *bash_profile globs (877 bytes, patch)
2014-07-28 03:34 UTC, Magdalen Berns (irc magpie)
none Details | Review
sh.lang: add globs *bashrc *profile and *bash_profile (908 bytes, patch)
2014-07-28 03:37 UTC, Magdalen Berns (irc magpie)
reviewed Details | Review
sh.lang: add globs for *bashrc and *profile files (859 bytes, patch)
2014-08-09 02:41 UTC, Magdalen Berns (irc magpie)
none Details | Review
sh.lang: add globs for *bashrc and *profile files (859 bytes, patch)
2014-08-09 02:45 UTC, Magdalen Berns (irc magpie)
none Details | Review
explicit .bashrc et al (898 bytes, patch)
2014-08-13 11:53 UTC, Magdalen Berns (irc magpie)
none Details | Review

Description Magdalen Berns (irc magpie) 2014-07-23 18:23:20 UTC
Gedit's looking really awesome these days, good work! So, this is just a small nit that would be a nice enhancement were it easy to implement. Not sure but anyway be nice if gedit were to recognise and prettify the following with bashy formatting instead of being plain old text by default like any other invisible file.

~/.bashrc ~/.profile and ~/.bash_profile

possible?

My gedit version is 3.12.2 in case that's useful.
Comment 1 Sébastien Wilmet 2014-07-23 18:43:25 UTC
It would be useful, indeed.
Comment 2 Paolo Borelli 2014-07-23 20:39:56 UTC
Should be just a matter of adding those to the sh.lang globs
Comment 3 Magdalen Berns (irc magpie) 2014-07-26 15:56:53 UTC
(In reply to comment #2)
> Should be just a matter of adding those to the sh.lang globs

Not familiar with the way gedit files and directories set up sorry but off hand I could'nt find what you were referring to in the git repo, sorry if this seems obvious but could you explain where's that is done, more precisely?
Comment 4 jessevdk@gmail.com 2014-07-26 16:38:54 UTC
See https://git.gnome.org/browse/gtksourceview/tree/data/language-specs/sh.lang#n28

It's a semicolon separated list of shell like globs to which file names are matched. You should be able to add .bashrc .profile and .bash_profile to the list.
Comment 5 Magdalen Berns (irc magpie) 2014-07-27 13:00:28 UTC
(In reply to comment #4)
> See
> https://git.gnome.org/browse/gtksourceview/tree/data/language-specs/sh.lang#n28
> 
> It's a semicolon separated list of shell like globs to which file names are
> matched. You should be able to add .bashrc .profile and .bash_profile to the
> list.

Awesome, thanks. I'll have a craic!
Comment 6 Magdalen Berns (irc magpie) 2014-07-28 03:34:52 UTC
Created attachment 281837 [details] [review]
add *bashrc *profile and *bash_profile globs
Comment 7 Magdalen Berns (irc magpie) 2014-07-28 03:37:01 UTC
Created attachment 281838 [details] [review]
sh.lang: add globs *bashrc *profile and *bash_profile
Comment 8 Sébastien Wilmet 2014-08-08 22:08:50 UTC
Review of attachment 281838 [details] [review]:

Thank you for the patch.
Please squash the two commits with 'git rebase -i'.

::: data/language-specs/sh.lang
@@ +26,3 @@
   <metadata>
     <property name="mimetypes">text/x-shellscript;application/x-shellscript;text/x-sh</property>
+    <property name="globs">*.sh;*bashrc;*bash_profile;*profile</property>

for *bashrc and *bash_profile, I think it's ok.
But for *profile, does it work with ".profile"? Because if a user has a simple text file ending with "profile", it'll be highlighted as a shell script…
Comment 9 Magdalen Berns (irc magpie) 2014-08-09 02:20:59 UTC
(In reply to comment #8)
> Review of attachment 281838 [details] [review]:
> 
> Thank you for the patch.
> Please squash the two commits with 'git rebase -i'.

What is the problem you refer to here? I am not following...

> 
> ::: data/language-specs/sh.lang
> @@ +26,3 @@
>    <metadata>
>      <property
> name="mimetypes">text/x-shellscript;application/x-shellscript;text/x-sh</property>
> +    <property name="globs">*.sh;*bashrc;*bash_profile;*profile</property>
> 
> for *bashrc and *bash_profile, I think it's ok.
> But for *profile, does it work with ".profile"? Because if a user has a simple
> text file ending with "profile", it'll be highlighted as a shell script…

I can't see where that might happen but I can take profile out or have it as $HOME/.profile if you prefer to be careful? If you decide you want to keep it in there's a good point though *bash_profile is already dealt with in *profile so that can probably go out in the case *profile stays, anyway.
Comment 10 Magdalen Berns (irc magpie) 2014-08-09 02:41:45 UTC
Created attachment 282957 [details] [review]
sh.lang: add globs for *bashrc and *profile files
Comment 11 Magdalen Berns (irc magpie) 2014-08-09 02:45:01 UTC
Created attachment 282958 [details] [review]
sh.lang: add globs for *bashrc and *profile files
Comment 12 jessevdk@gmail.com 2014-08-09 08:58:50 UTC
Why not just match the actual filename? i.e. ".profile" instead of "*profile"? Like said before *profile is to general and will cause normal files ending on profile to be misclassified as shell scripts.
Comment 13 Magdalen Berns (irc magpie) 2014-08-12 19:10:16 UTC
(In reply to comment #12)
> Why not just match the actual filename? i.e. ".profile" instead of "*profile"?
> Like said before *profile is to general and will cause normal files ending on
> profile to be misclassified as shell scripts.

Ah, ok I see what you mean now.

If you only put .profile then you miss out /etc/profile and etc/bashrc and for a plain text file profile.txt it would still format plain text since it's only going to format as a shell script the file ends in *profile with no .txt at the end anyways. That seems unlikely to me so the patch is personally how I'd have it, for my own purposes, anyway.

That said I wouldn't have a problem changing to .profile and .bashrc just that it is worth noting that this won't cover the root profile and bash files so in that case it might be worth putting something explicit in for these files too otherwise they'll not get the benefit of shell formatting.
Comment 14 Sébastien Wilmet 2014-08-12 20:15:26 UTC
You can have text files without the .txt extension. (.txt comes from Windows)
Comment 15 Magdalen Berns (irc magpie) 2014-08-13 08:45:30 UTC
(In reply to comment #14)
> You can have text files without the .txt extension. (.txt comes from Windows)

???

A riddle:

a) A plain text file ending in profile

b) A shell script with the file ending profile

c) A solution to 733624

One of these is very unlikely to exist, another is almost certain to exist (at least once) and the other is not ever going to happen at this rate.
Comment 16 jessevdk@gmail.com 2014-08-13 08:52:22 UTC
On my system I already have 91 files ending on profile, I don't think it's _very_ uncommon, and it would not be very future proof. Also, I don't know how many people try to open /etc/profile with sudo in gedit, but I can take an educated guess that it does not happen very often. If you do, it's a matter of selecting the highlighting once and saving the file. The highlighting mode will be saved in metadata.
Comment 17 Magdalen Berns (irc magpie) 2014-08-13 11:53:30 UTC
Created attachment 283277 [details] [review]
explicit .bashrc et al

(In reply to comment #16)
> On my system I already have 91 files ending on profile, I don't think it's
> _very_ uncommon, and it would not be very future proof. Also, I don't know how
> many people try to open /etc/profile with sudo in gedit, but I can take an
> educated guess that it does not happen very often. If you do, it's a matter of
> selecting the highlighting once and saving the file. The highlighting mode will
> be saved in metadata.

I said "files" in a) and b) with no adjective there, right?

What do you think the probability of anyone making a decision is according to the CLT of pointless arguments about non-issues that nobody cares about in c) of this riddle, then?

It really is this simple:

(In reply to comment #13)
> (In reply to comment #12)
> > Why not just match the actual filename? i.e. ".profile" instead of "*profile"?
> I wouldn't have a problem changing to .profile and .bashrc 

So i.e, I am not going to agree, but I do not care enough to argue because ultimately, you say tomato, I say it properly ;-) and ultimately none of us have any way of determining whether our intuition is right because that's not how statistics and probability work. So, it's up to the maintainers to be clear about what they want. Failing that, here is a second alternative patch so there is a choice to make.
Comment 18 Sébastien Wilmet 2014-08-13 12:30:01 UTC
I've modified a little the latest patch and pushed it:
https://git.gnome.org/browse/gtksourceview/commit/?id=4a774bd8dd1a362fa03c75000dc173efdc273188

We were talking about "*profile", not "*bashrc". As I said above, I think "*bashrc" is fine.
Comment 19 Magdalen Berns (irc magpie) 2014-08-13 23:18:43 UTC
(In reply to comment #18)
> I've modified a little the latest patch and pushed it:
> https://git.gnome.org/browse/gtksourceview/commit/?id=4a774bd8dd1a362fa03c75000dc173efdc273188
> 
> We were talking about "*profile", not "*bashrc". As I said above, I think
> "*bashrc" is fine.

Totally, but I genuinely cannot see the the logical difference between the treatments for bashrc or profile nor can I understand why nobody's bothered about poor old bash_profile's fate.

In any case though, thank you for deciding on one of the patches. That's awesome! It was great to get the opportunity to contribute to gtksourceview and bring this cool little enhancement to gedit...  \o/

Thanks for the help everyone :-)