Skip to content

Far behind sh/bash #37

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

Closed
xeruf opened this issue Aug 9, 2021 · 9 comments
Closed

Far behind sh/bash #37

xeruf opened this issue Aug 9, 2021 · 9 comments

Comments

@xeruf
Copy link

xeruf commented Aug 9, 2021

When editing a zsh script in neovim I get much richer syntax highlighting using the sh or bash filetype. Isn't this somehow based on sh? Is this related to neovim?

@chrisbra
Copy link
Owner

chrisbra commented Aug 9, 2021

First of all, shell language is very complex. I do not intend to allow to color every possible obscure shell language feature. Look at the default shell syntax file that comes with vim/neovim and at the same time, how many different bug reports are opened. So a simpler zsh syntax is actually a feature. However, if you are missing something specific, please let me know and I see if I can support this.

@chrisbra chrisbra closed this as completed Aug 9, 2021
@xeruf
Copy link
Author

xeruf commented Aug 10, 2021

Here is an illustration:

ft=zsh

ft=sh

sh highlights alias & function definitions, as well as commands and flags separately, which I would expect the zsh highlighting to do as well.

@chrisbra
Copy link
Owner

wow, that is very shiny and in my opinion a bit too much.

Having said that, I am not against enhancing the current syntax script, but we need to be very careful, not to introduce regressions while keeping it fast and performant.

So I'll leave that to someone who wants to actually spend time on it, I am open for PRs. I personally don't feel comfortable making those adjustments :(

@xeruf
Copy link
Author

xeruf commented Aug 10, 2021

My expectation would be that zsh is exactly the same as sh or bash with tiny adjustments for zsh-specific syntax if needed. From my quick testing it seems that bash and sh are essentially equivalent as well.

@xeruf
Copy link
Author

xeruf commented Aug 10, 2021

Aha!

File: ftplugin/bash.vim

" Vim filetype plugin file
" Language: bash
" Maintainer:   Bram Moolenaar
" Last Changed: 2019 Jan 12
"
" This is not a real filetype plugin.  It allows for someone to set 'filetype'
" to "bash" in the modeline, and gets the effect of filetype "sh" with
" b:is_bash set.  Idea from Mahmode Al-Qudsi.

if exists("b:did_ftplugin")
  finish
endif

unlet! b:is_sh
unlet! b:is_kornshell
let b:is_bash = 1

runtime! ftplugin/sh.vim ftplugin/sh_*.vim ftplugin/sh/*.vim

@danielshahaf
Copy link
Contributor

So I'll leave that to someone who wants to actually spend time on it, I am open for PRs.

Then reopen this issue?

@danielshahaf
Copy link
Contributor

Here is an illustration:

FWIW, I think I like this.

It would be interesting to compare that and zsh-syntax-highlighting's defaults: for instance, default highlighting of delimiter quotes and lack of highlighting of command words. (I'm not unaffiliated.)

@xeruf
Copy link
Author

xeruf commented Aug 11, 2021

Yes, it would be great to somewhat unify these tools, Emacs highlighting could be another place to look.

@danielshahaf
Copy link
Contributor

Somewhat related: zsh-users/zsh-syntax-highlighting#327. That issue imagined other parser consumers would be written in zsh, as opposed to VimL/elisp, but I'm putting it here for context (and in the hope that one day it'll turn out to be the proverbial apple that falls on an unsuspecting head).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants