Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@
"tags": [
"language"
],
"version": "0.2"
"version": "0.3"
},
{
"description": "Syntax for ssh & sshd config files",
Expand Down
35 changes: 27 additions & 8 deletions plugins/language_sh.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
-- 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$", "%.zsh$", "%.fish$" },
headers = "^#!.*bin.*sh\n",
files = { "%.sh$", "%.bash$", "%.bashrc$", "%.bash_profile$", "%.profile$", "%.zprofile$", "%.zsh$", "%.zshrc$", "%.fish$" },
headers = "^#!.*bin.*sh",
comment = "#",
patterns = {
-- $# is a bash special variable and the '#' shouldn't be interpreted
-- 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
Expand All @@ -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" },
Expand Down Expand Up @@ -95,4 +115,3 @@ syntax.add {
["false"] = "literal"
}
}