Kate bash syntax highlighting subshell in quotes bug fix
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4124
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
If you use kate, and do bash with syntax like

:: Code ::
if [ "$( some test )" -gt 0 ];then
do stuff


you've probably noticed that the quote never closes after the subshell, which turns all the code after that quote color, which of course is not what you want, it's totally unreadable.

I've been too lazy to find the actual syntax xml file fix, but this is a very easy way to resolve it, which I found by just changing syntax files setting in tools -> highlighting in kate.

The short story: zsh.xml or zsh works fine, and handles subshells that are quoted correctly, why this is still a bug in debian's xml at this point is totally beyond me, but here's the fix.

make a backup copy of:

:: Code ::
/usr/share/kde4/apps/katepart/syntax/bash.xml


then remove it:
:: Code ::
rm /usr/share/kde4/apps/katepart/syntax/bash.xml


put it somewhere safe, whereever. If you have different system paths, use:
:: Code ::
locate bash.xml
to find the files, one will be in /usr probably and one will be in $HOME/.kde somewhere.

Next remove the cached copy of the bash.xml from here:

:: Code ::
rm $HOME/.kde/share/apps/katepart/syntax/bash.xml


now copy the /usr zsh.xml file to bash.xml like so:

:: Code ::
cp /usr/share/kde4/apps/katepart/syntax/zsh.xml /usr/share/kde4/apps/katepart/syntax/bash.xml


Now open up the backup of the bash.xml file and your copied zsh.xml file, and copy this block from bash.xml backup:

:: Code ::
<language name="Bash" version="2.15" kateversion="2.4" section="Scripts" extensions="*.sh;*.bash;*.ebuild;*.eclass;.bashrc;.bash_profile;.bash_login;.profile" mimetype="application/x-shellscript" casesensitive="1" author="Wilbert Berendsen (wilbert@kde.nl)" license="LGPL">


It will look something like that, depending on your kate/kde version.

Open up the newly copied bash.xml, which will have at the top this line, or something like it:
:: Code ::
<language name="Zsh" version="0.1" kateversion="2.4" section="Scripts" extensions="*.sh;*.zsh;.zshrc;.zprofile;.zlogin;.zlogout;.profile" mimetype="application/x-shellscript" casesensitive="1" author="Jonathan Kolberg (bulldog98@kubuntu-de.org)" license="LGPL">


replace that block with the first bash one above, then save the new bash.xml file.

This bug is really old, and i have to assume the bash.xml file maintainer simply does not use bash, or uses so little bash that he never sees this bug, why it still exists today, in 2013, almost 2014, is beyond me, it's not like bash subshells are unusual or anything, it's a part of the language.

Anyway, now you have your new bash.xml file, which is just the zsh.xml file with a faked <language block, it works pretty well, I haven't seen any real glitches using zsh, but of course, it would be REALLY nice if kate would just have a proper bash.xml syntax file in the first place, this is one of those things I thought would be fixed since it's such a massive, glaring, error, that any coder would/will see instantly, it's hard to see how it could keep existing, but then again, debian's grub 2 still does not support LABEL either as far as I know, and those bugs/patches were uploaded years ago too.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours