-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add .zprofile and .zshrc to language_sh
and fix header pattern.
#470
base: master
Are you sure you want to change the base?
Conversation
Now files like `.zprofile` and `.bash_profile` are highlighted.
It's because of nested What do you think about something like: index 83e98b5..8396464 100644
--- a/plugins/language_sh.lua
+++ b/plugins/language_sh.lua
@@ -1,6 +1,16 @@
-- mod-version:3
local syntax = require "core.syntax"
+local string_syntax = {
+ name = "Shell script string",
+ patterns = {
+ { pattern = {"%${", "}"}, type = "keyword2", syntax = ".sh" },
+ { pattern = "[^%$]", type = "string" },
+ { pattern = "%$[^{]", type = "string" },
+ },
+ symbols = {}
+}
+
syntax.add {
name = "Shell script",
files = { "%.sh$", "%.bash$", "%.bashrc$", "%.bash_profile$", "%.profile$", "%.zprofile$", "%.zsh$", "%.zshrc$", "%.fish$" },
@@ -11,11 +21,11 @@ syntax.add {
-- as a comment.
{ pattern = "$[%a_@*#][%w_]*", type = "keyword2" },
-- Comments
- { pattern = "#.*\n", type = "comment" },
+ { pattern = "#.*", type = "comment" },
-- Strings
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "'", "'", '\\' }, type = "string" },
- { pattern = { '`', '`', '\\' }, type = "string" },
+ { pattern = { '"', '"', '\\' }, type = "string", syntax = string_syntax },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = { '`', '`', '\\' }, type = "string", syntax = ".sh" },
-- Ignore numbers that start with dots or slashes
{ pattern = "%f[%w_%.%/]%d[%d%.]*%f[^%w_%.]", type = "number" },
-- Operators
@@ -35,12 +45,14 @@ syntax.add {
-- Match variable assignments
{ pattern = "[_%a][%w_]+%f[%+=]", type = "keyword2" },
-- Match variable expansions
- { pattern = "${.*}", type = "keyword2" },
+ { pattern = { "${", "}", "\\" }, type = "keyword2", syntax = ".sh" },
{ pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" },
-- Functions
{ pattern = "[%a_%-][%w_%-]*[%s]*%f[(]", type = "function" },
-- Everything else
{ pattern = "[%a_][%w_]*", type = "symbol" },
+ -- Catch escaped } - to avoid closing a ${...\}...} prematurely
+ { pattern = "\\}", type = "normal" },
},
symbols = {
["case"] = "keyword", Also, would you mind bumping the plugin version in |
Hi, thanks for the explanation but I'm still not sure why it fixes the issue 😅 I know that I know the problem is line 5 in the script, something happens that makes it seem like the last } wasn't there I think. If it was the other way around, that .* had the issue and .- fixes it it would make sense, but anyway I just tested the changes you gave (I applied them to the file of my fork just in case) and something broke. This is how part of the bemoji script looks with the changes I did: And this is how it looks with the proposed changes:
Will do! |
The issue is caused by So I guess we can't just say that inside index 83e98b5..bbd93f1 100644
--- a/plugins/language_sh.lua
+++ b/plugins/language_sh.lua
@@ -1,6 +1,26 @@
-- mod-version:3
local syntax = require "core.syntax"
+local expansion_syntax = {
+ name = "Shell script parameter expansion",
+ symbols = {}
+}
+expansion_syntax.patterns = {
+ { pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax },
+ { pattern = "[^%$}]+", type = "string" },
+ { pattern = "[%$}]", type = "string" },
+}
+
+local string_syntax = {
+ name = "Shell script string",
+ patterns = {
+ { pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax },
+ { pattern = '[^%$"]+', type = "string" },
+ { pattern = '[%$"]', type = "string" },
+ },
+ symbols = {}
+}
+
syntax.add {
name = "Shell script",
files = { "%.sh$", "%.bash$", "%.bashrc$", "%.bash_profile$", "%.profile$", "%.zprofile$", "%.zsh$", "%.zshrc$", "%.fish$" },
@@ -11,11 +31,11 @@ syntax.add {
-- as a comment.
{ pattern = "$[%a_@*#][%w_]*", type = "keyword2" },
-- Comments
- { pattern = "#.*\n", type = "comment" },
+ { pattern = "#.*", type = "comment" },
-- Strings
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "'", "'", '\\' }, type = "string" },
- { pattern = { '`', '`', '\\' }, type = "string" },
+ { pattern = { '"', '"', '\\' }, type = "string", syntax = string_syntax },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = { '`', '`', '\\' }, type = "string", syntax = ".sh" },
-- Ignore numbers that start with dots or slashes
{ pattern = "%f[%w_%.%/]%d[%d%.]*%f[^%w_%.]", type = "number" },
-- Operators
@@ -35,7 +55,7 @@ syntax.add {
-- Match variable assignments
{ pattern = "[_%a][%w_]+%f[%+=]", type = "keyword2" },
-- Match variable expansions
- { pattern = "${.*}", type = "keyword2" },
+ { pattern = { "${", "}", '\\' }, type = "keyword2", syntax = expansion_syntax },
{ pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" },
-- Functions
{ pattern = "[%a_%-][%w_%-]*[%s]*%f[(]", type = "function" }, In the future we might even improve the expansion syntax, to highlight inside it too. |
That one works fine, thanks! I will apply the patch.
something I would like to see is variables inside |
Thanks to @Guldoman for the fix
Something like this maybe: index 8f38ca8..a043eb2 100644
--- a/plugins/language_sh.lua
+++ b/plugins/language_sh.lua
@@ -7,16 +7,18 @@ local expansion_syntax = {
}
expansion_syntax.patterns = {
{ pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax },
- { pattern = "[^%$}]+", type = "string" },
- { pattern = "[%$}]", type = "string" },
+ { pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" },
+ { pattern = "[^%$}]+", type = "string" },
+ { pattern = "[%$}]", type = "string" },
}
local string_syntax = {
name = "Shell script string",
patterns = {
{ pattern = { "%${", "}", "\\" }, type = "keyword2", syntax = expansion_syntax },
- { pattern = '[^%$"]+', type = "string" },
- { pattern = '[%$"]', type = "string" },
+ { pattern = "$[%d$%a_@*][%w_]*", type = "keyword2" },
+ { pattern = '[^%$"]+', type = "string" },
+ { pattern = '[%$"]', type = "string" },
},
symbols = {}
} We should probably also add something about |
That works fine, but I had to change my color profile in lite-xl because the one I had been using doesn't differentiate the change. Do I apply the changes as well?
And I just noticed that subshells don't get highlighted. In theory it just has to match $() but not what's inside of it, my little knowledge of regexes comes from sed, grep and awk so let's see if I can do something here lol. edit: adding edit2: Although comparing it to gtksourceview it really isn't that much different, when you type a What do you think? |
Now
.zshrc
gets recognized and scripts that have flags in their shebang also work.However my
.zprofile
still doesn't work 🤔When completed this will fix all the issues at #469