IF the file you are editing has a fixed name, a predictable file name pattern or a fixed shebang, or file content, then you can use the ApplySyntax plugin:
- Cmd/Ctrl+Shift+P > Package Control: Install Package > type ApplySyntax > Enter
- Cmd/Ctrl+Shift+P > type ApplySyntax > pick ApplySyntax:Settings
You’ll see in the default config in the left panel that for example .profile files are treated as "ShellScript/Bash".
For fuzzy matching have a look at the predefined globmatch rules, for example the ootb rule for bash:
{
"syntax": [
"ShellScript/Bash",
"ShellScript/Shell-Unix-Generic"
],
"extensions": ["bash", "sh", "zsh", "bashrc", "ash", ".profile"],
"rules": [
{
"globmatch": [
"**/.bash*",
"**/.z@(shrc|shenv|profile|login|logout)*"
]
},
{"interpreter": "bash"},
{"interpreter": "zsh"}
]
}
I needed this for my ~/.aliases file, so one option is to add a shebang in the first line in the #!/usr/bin/bash, while another option is keeping the file as is without a shebang and in the ApplySyntax user config override the default extensions for bash with:
"extensions": ["bash", "sh", "zsh", "bashrc", "ash", ".profile", ".aliases"],
ps. I have no affiliation with the plugin developer