Loading ...
Sorry, an error occurred while loading the content.

Re: sh vs bash syntax coloring

Expand Messages
  • ZyX
    Reply to message «Re: sh vs bash syntax coloring», sent 12:31:16 01 August 2011, Monday ... You can put this option somewher in ~/.zshenv. Or, better, use
    Message 1 of 18 , Aug 1, 2011
    • 0 Attachment
      Reply to message «Re: sh vs bash syntax coloring»,
      sent 12:31:16 01 August 2011, Monday
      by ranousse@...:

      > In the first case
      > I would like like that :!shell_cmd is runed with bash.
      > (In fact the main reason is that sometimes I write things like
      >
      > :!action="xpdf -option"; ...; $action file
      >
      > and by default zsh does not split $action in 2 strings, there's an
      > option but it needs one more command).
      You can put this option somewher in ~/.zshenv. Or, better, use zsh syntax for
      it:
      !action=(xpdf -option) ; ... ; $action file
      !action="xpdf -option" ; ... ; ${(z)action} file
      !action="xpdf -option" ; ... ; $=action file
      in last case it is just one more character to type, in the first case you should
      type exactly the same number of characters, but two of them are different. These
      methods are not the same under all circumstances, but are the same here.
      I actually hate using bash for scripting: how do you like using
      command "${array[@]}"
      where in zsh you type just
      command $array
      . You have to also turn your mind on remembering that you must use quotes around
      any parameter if you want it to come in one piece and unmodified.

      I would likely choose zsh, perl, python for scripting but not bash.

      Original message:
      > On 31/07 13:10, Gary Johnson wrote:
      > > I'm not sure I understand the problem. If you write your shell
      > > scripts with
      > >
      > > #!/bin/bash
      > >
      > > as the first line, they will be executed by bash, regardless of the
      > > shell they were started from.
      >
      > My problem with #!/bin/bash and #!/bin/sh is solved. Actually it did not
      > concerned wich shell is used to run the script but the syntax
      > highlighting. I have no problem about wich shell is used to run the
      > script.
      >
      > My question about which shell is used between bash and zsh concerns
      >
      > :!shell_cmd and :sh.
      >
      > In the first case
      > I would like like that :!shell_cmd is runed with bash.
      > (In fact the main reason is that sometimes I write things like
      >
      > :!action="xpdf -option"; ...; $action file
      >
      > and by default zsh does not split $action in 2 strings, there's an
      > option but it needs one more command).
      >
      > And for :sh, as it's a classical interactive shell, I would prefer zsh.
      >
      > > What behavior do you want from
      > >
      > > :!shell_command
      > >
      > > that you get from bash that you don't get from zsh?
      > > You could create a ~/.bashrc that contains just
      > >
      > > exec /bin/zsh
      > >
      > > and that would start zsh as your interactive shell, but I don't know
      > > whether the behavior would be the same as if you executed ":sh" with
      > > sh=zsh.
      >
      > This seems to work. But I loose the possibility of running interactive
      > bash if I want. Interesting however.
    • ranousse@gmx.com
      ... Ok thank you. I think this will be sufficient for my need. Actually I didn t say bash was better than zsh, but I learnt sh syntax first (not even bash, so
      Message 2 of 18 , Aug 1, 2011
      • 0 Attachment
        > You can put this option somewher in ~/.zshenv. Or, better, use zsh syntax for
        > it:
        > !action=(xpdf -option) ; ... ; $action file
        > !action="xpdf -option" ; ... ; ${(z)action} file
        > !action="xpdf -option" ; ... ; $=action file
        > in last case it is just one more character to type, in the first case you should
        > type exactly the same number of characters, but two of them are different. These
        > methods are not the same under all circumstances, but are the same here.
        > I actually hate using bash for scripting: how do you like using
        > command "${array[@]}"
        > where in zsh you type just
        > command $array
        > . You have to also turn your mind on remembering that you must use quotes around
        > any parameter if you want it to come in one piece and unmodified.
        >
        > I would likely choose zsh, perl, python for scripting but not bash.

        Ok thank you. I think this will be sufficient for my need.
        Actually I didn't say bash was better than zsh, but I learnt sh syntax
        first (not even bash, so no array at all it seems) and I don't know zsh
        one. I only write small scripts ;-)
        But I'm sure you're right.

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Leiking
        zsh. ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to. For more information,
        Message 3 of 18 , Aug 1, 2011
        • 0 Attachment
          zsh.

          2011/8/1 <ranousse@...>:
          >> You can put this option somewher in ~/.zshenv. Or, better, use zsh syntax for
          >> it:
          >>     !action=(xpdf -option) ; ... ; $action file
          >>     !action="xpdf -option" ; ... ; ${(z)action} file
          >>     !action="xpdf -option" ; ... ; $=action file
          >> in last case it is just one more character to type, in the first case you should
          >> type exactly the same number of characters, but two of them are different. These
          >> methods are not the same under all circumstances, but are the same here.
          >> I actually hate using bash for scripting: how do you like using
          >>     command "${array[@]}"
          >> where in zsh you type just
          >>     command $array
          >> . You have to also turn your mind on remembering that you must use quotes around
          >> any parameter if you want it to come in one piece and unmodified.
          >>
          >> I would likely choose zsh, perl, python for scripting but not bash.
          >
          > Ok thank you. I think this will be sufficient for my need.
          > Actually I didn't say bash was better than zsh, but I learnt sh syntax
          > first (not even bash, so no array at all it seems) and I don't know zsh
          > one. I only write small scripts ;-)
          > But I'm sure you're right.
          >
          > --
          > You received this message from the "vim_use" maillist.
          > Do not top-post! Type your reply below the text you are replying to.
          > For more information, visit http://www.vim.org/maillist.php
          >

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Benjamin R. Haskell
          ... Yes, they are: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html $(command) - #tag_02_06_03 - command substitution $((n+1)) -
          Message 4 of 18 , Aug 1, 2011
          • 0 Attachment
            On Sun, 31 Jul 2011, Thilo Six wrote:

            > ranousse@... wrote the following on 31.07.2011 12:42
            >
            > Hello
            >
            >> I'm not very happy with syntax coloring of sh scripts (starting with
            >> #!/bin/sh). For example, things like $(command), $((n+1)) or
            >> ${var%.txt} are very badly displayed. However they are part of POSIX
            >> sh I think.

            Yes, they are:

            http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
            $(command) - #tag_02_06_03 - command substitution
            $((n+1)) - #tag_02_06_04 - arithmetic expansion
            ${var%.txt} - #tag_02_06_02 (last ¶) - parameter expansion


            >> Do you know a simple hack to correct this. Something that could
            >> interest me would be always using bash syntax coloring even with
            >> #!/bin/sh at the beginning.
            >>
            >> I thought of modelines but vim seems to use the same syntax file for
            >> sh and bash and thus I cannot use something like
            >> # vi: syntax=bash
            >> or
            >> # vi: ft=bash
            >>
            >
            >
            > ,----[ :h ft-sh-syntax ]----------------------
            >
            > < bash: >
            > let g:is_bash = 1
            > `---------------------------------------------

            That solves the problem since the OP wants bash syntax. I don't. Is
            there a reason the constructs mentioned aren't included in "plain 'sh'"
            mode?

            --
            Best,
            Ben

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Charles Campbell
            ... Just to be complete, please read :help ft-syntax-sh (g:is_bash is covered there, for example). Regards, Chip Campbell -- You received this message from
            Message 5 of 18 , Aug 1, 2011
            • 0 Attachment
              ranousse@... wrote:
              > On 31/07 13:49, Thilo Six wrote:
              >
              >> ,----[ :h ft-sh-syntax ]----------------------
              >>
              >> < bash:>
              >> let g:is_bash = 1
              >> `---------------------------------------------
              >>
              > So there is no trick at all, I only have to choose the right option.
              > Thank you very much.
              >
              Just to be complete, please read :help ft-syntax-sh (g:is_bash is
              covered there, for example).

              Regards,
              Chip Campbell

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Thilo Six
              Charles Campbell wrote the following on 01.08.2011 18:17 Hello Charles, I think here is a typo: -- -- ... ^ `- s:ft-syntax-sh:ft-sh-syntax: :help
              Message 6 of 18 , Aug 1, 2011
              • 0 Attachment
                Charles Campbell wrote the following on 01.08.2011 18:17

                Hello Charles,

                I think here is a typo:

                -- <snip> --

                > Just to be complete, please read :help ft-syntax-sh (g:is_bash is
                ^
                `- s:ft-syntax-sh:ft-sh-syntax:
                ':help ft-syntax-sh' returns E419 to me

                > covered there, for example).
                >
                > Regards,
                > Chip Campbell
                >

                Regards,
                --
                bye Thilo

                4096R/0xC70B1A8F
                721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • ZyX
                Reply to message «Re: sh vs bash syntax coloring», sent 18:28:38 01 August 2011, Monday ... ?
                Message 7 of 18 , Aug 1, 2011
                • 0 Attachment
                  Reply to message «Re: sh vs bash syntax coloring»,
                  sent 18:28:38 01 August 2011, Monday
                  by Leiking:

                  > zsh.
                  ?

                  Original message:
                  > zsh.
                  >
                  > 2011/8/1 <ranousse@...>:
                  > >> You can put this option somewher in ~/.zshenv. Or, better, use zsh
                  > >> syntax for it:
                  > >> !action=(xpdf -option) ; ... ; $action file
                  > >> !action="xpdf -option" ; ... ; ${(z)action} file
                  > >> !action="xpdf -option" ; ... ; $=action file
                  > >> in last case it is just one more character to type, in the first case
                  > >> you should type exactly the same number of characters, but two of them
                  > >> are different. These methods are not the same under all circumstances,
                  > >> but are the same here. I actually hate using bash for scripting: how do
                  > >> you like using command "${array[@]}"
                  > >> where in zsh you type just
                  > >> command $array
                  > >> . You have to also turn your mind on remembering that you must use
                  > >> quotes around any parameter if you want it to come in one piece and
                  > >> unmodified.
                  > >>
                  > >> I would likely choose zsh, perl, python for scripting but not bash.
                  > >
                  > > Ok thank you. I think this will be sufficient for my need.
                  > > Actually I didn't say bash was better than zsh, but I learnt sh syntax
                  > > first (not even bash, so no array at all it seems) and I don't know zsh
                  > > one. I only write small scripts ;-)
                  > > But I'm sure you're right.
                  > >
                  > > --
                  > > You received this message from the "vim_use" maillist.
                  > > Do not top-post! Type your reply below the text you are replying to.
                  > > For more information, visit http://www.vim.org/maillist.php
                • Charles Campbell
                  ... Sorry, that should ve been :help ft-sh-syntax . Regards, Chip Campbell -- You received this message from the vim_use maillist. Do not top-post! Type
                  Message 8 of 18 , Aug 1, 2011
                  • 0 Attachment
                    Thilo Six wrote:
                    > Charles Campbell wrote the following on 01.08.2011 18:17
                    >
                    > Hello Charles,
                    >
                    > I think here is a typo:
                    >
                    > -- <snip> --
                    >
                    >
                    >> Just to be complete, please read :help ft-syntax-sh (g:is_bash is
                    >>
                    > ^
                    > `- s:ft-syntax-sh:ft-sh-syntax:
                    > ':help ft-syntax-sh' returns E419 to me
                    >
                    Sorry, that should've been :help ft-sh-syntax .

                    Regards,
                    Chip Campbell

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • Simon Nicolussi
                    ... Not all shells support command substitution via $(...), even though it is required by POSIX. The /bin/sh in Solaris comes to mind. If you know you re using
                    Message 9 of 18 , Aug 1, 2011
                    • 0 Attachment
                      Benjamin R. Haskell wrote:
                      > That solves the problem since the OP wants bash syntax. I don't.
                      > Is there a reason the constructs mentioned aren't included in "plain
                      > 'sh'" mode?

                      Not all shells support command substitution via $(...), even though it
                      is required by POSIX. The /bin/sh in Solaris comes to mind. If you know
                      you're using a compatible shell, you can specify:

                      let g:is_posix = 1

                      --
                      Simon Nicolussi, <Simon.Nicolussi@...>
                      http://homepage.uibk.ac.at/~csag9583/
                    • Benjamin R. Haskell
                      ... [Just FYI:] The /bin/sh in Solaris 10 works fine. Wouldn t surprise me if 5.8 or prior didn t... ... Seems like this should be the default, but okay. I
                      Message 10 of 18 , Aug 1, 2011
                      • 0 Attachment
                        On Mon, 1 Aug 2011, Simon Nicolussi wrote:

                        > Benjamin R. Haskell wrote:
                        >> That solves the problem since the OP wants bash syntax. I don't. Is
                        >> there a reason the constructs mentioned aren't included in "plain
                        >> 'sh'" mode?
                        >
                        > Not all shells support command substitution via $(...), even though it
                        > is required by POSIX. The /bin/sh in Solaris comes to mind.

                        [Just FYI:] The /bin/sh in Solaris 10 works fine. Wouldn't surprise me
                        if 5.8 or prior didn't...


                        > If you know you're using a compatible shell, you can specify:
                        >
                        > let g:is_posix = 1

                        Seems like this should be the default, but okay. I see it in the help
                        now. Presuming this doesn't affect zsh-detection, I'll just add it and
                        be done.

                        --
                        Thanks,
                        Ben

                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • Charles Campbell
                        ... You ll also find in the help for ft-sh-syntax the sentence: No need to quote RFCs or market penetration statistics in error reports, please -- just select
                        Message 11 of 18 , Aug 2, 2011
                        • 0 Attachment
                          Benjamin R. Haskell wrote:
                          > On Mon, 1 Aug 2011, Simon Nicolussi wrote:
                          >
                          >> Benjamin R. Haskell wrote:
                          >>> That solves the problem since the OP wants bash syntax. I don't.
                          >>> Is there a reason the constructs mentioned aren't included in "plain
                          >>> 'sh'" mode?
                          >>
                          >> Not all shells support command substitution via $(...), even though
                          >> it is required by POSIX. The /bin/sh in Solaris comes to mind.
                          >
                          > [Just FYI:] The /bin/sh in Solaris 10 works fine. Wouldn't surprise
                          > me if 5.8 or prior didn't...
                          >
                          >
                          >> If you know you're using a compatible shell, you can specify:
                          >>
                          >> let g:is_posix = 1
                          >
                          > Seems like this should be the default, but okay. I see it in the help
                          > now. Presuming this doesn't affect zsh-detection, I'll just add it
                          > and be done.
                          >
                          You'll also find in the help for ft-sh-syntax the sentence:

                          No need to quote RFCs or market penetration statistics in error
                          reports, please -- just select the default version of the sh your system
                          uses in your <.vimrc>.

                          That's there because posix/ksh users like to quote RFCs about how the
                          default should be is_posix, and bash users like to quote market
                          penetration statistics to insist that the default should be is_bash. I
                          have the Bourne shell as default, not because I particularly like it the
                          best or anything (I'm a is_kornshell user, myself), but to encourage
                          users to make an informed choice.

                          However, please try v117 of sh.vim; it now has some logic using
                          resolve() to attempt to guess which shell is wanted. It won't be
                          perfect; for example, what shell should be used with .profile? On my
                          system, /bin/sh is linked to bash, and so the guessing logic will come
                          up with setting g:is_bash to one; however, my login shell is ksh, and so
                          .profile should be interpreted with g:is_kornshell = 1. The guess will
                          only be made if no g:is_posix, g:is_kornshell, g:is_bash, or g:is_sh exists.

                          You may get v117 from my website:
                          http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax .

                          Regards,
                          Chip Campbell

                          --
                          You received this message from the "vim_use" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        Your message has been successfully submitted and would be delivered to recipients shortly.