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

Formatting bash scripts

Expand Messages
  • Russell Shaw
    Hi, Is there a tool for setting the right indentation formatting for bash scripts?
    Message 1 of 10 , Nov 5, 2003
      Hi,
      Is there a tool for setting the right indentation
      formatting for bash scripts?
    • Amin
      ... You could try ... gulp ... Emacs ... Gulp, Yawar Amin
      Message 2 of 10 , Nov 5, 2003
        Russell Shaw wrote:
        > Hi,
        > Is there a tool for setting the right indentation
        > formatting for bash scripts?
        >
        >

        You could try ... gulp ... Emacs ...


        Gulp,
        Yawar Amin
      • Gary Johnson
        ... You mean something other than $VIMRUNTIME/indent/sh.vim? It seems to do pretty well except for case labels. That is, it formats a case command as case
        Message 3 of 10 , Nov 5, 2003
          On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
          > Hi,
          > Is there a tool for setting the right indentation
          > formatting for bash scripts?

          You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
          to do pretty well except for case labels. That is, it formats a
          case command as

          case $name in
          foo)
          echo this
          ;;
          bar)
          echo that
          ;;
          esac

          instead of as

          case $name in
          foo)
          echo this
          ;;
          bar)
          echo that
          ;;
          esac

          Does anyone have a fix for this?

          Gary

          --
          Gary Johnson | Agilent Technologies
          garyjohn@... | Wireless Division
          | Spokane, Washington, USA
        • Keith Roberts
          ... You could change global/indent/sh.vim to subtract an indent when a case is defined. This would involve something like setting g:sh_case when case is
          Message 4 of 10 , Nov 5, 2003
            >-----Original Message-----
            >From: Gary Johnson [mailto:garyjohn@...]
            >Sent: Wednesday, November 05, 2003 10:45 AM
            >To: vim@...
            >Subject: Re: Formatting bash scripts
            >
            >On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
            >> Hi,
            >> Is there a tool for setting the right indentation
            >> formatting for bash scripts?
            >
            >You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
            >to do pretty well except for case labels. That is, it formats a
            >case command as
            >
            > case $name in
            > foo)
            > echo this
            > ;;
            > bar)
            > echo that
            > ;;
            > esac
            >
            >instead of as
            >
            > case $name in
            > foo)
            > echo this
            > ;;
            > bar)
            > echo that
            > ;;
            > esac
            >
            >Does anyone have a fix for this?

            You could change global/indent/sh.vim to subtract an indent when a case is
            defined. This would involve something like setting g:sh_case when 'case' is
            encountered, and unsetting it when 'esac' is encountered; then reducing the
            indent for lines ending in ')' iff g:sh_case is set.

            Perhaps someone has a better solution?
          • Gary Johnson
            ... I m not very familiar with indent scripts, but I thought about tinkering with this one. The problem I had was distinguishing case labels (actually
            Message 5 of 10 , Nov 5, 2003
              On 2003-11-05, Keith Roberts <kroberts@...> wrote:
              > >-----Original Message-----
              > >From: Gary Johnson [mailto:garyjohn@...]
              > >Sent: Wednesday, November 05, 2003 10:45 AM
              > >To: vim@...
              > >Subject: Re: Formatting bash scripts
              > >
              > >On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
              > >> Hi,
              > >> Is there a tool for setting the right indentation
              > >> formatting for bash scripts?
              > >
              > >You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
              > >to do pretty well except for case labels. That is, it formats a
              > >case command as
              > >
              > > case $name in
              > > foo)
              > > echo this
              > > ;;
              > > bar)
              > > echo that
              > > ;;
              > > esac
              > >
              > >instead of as
              > >
              > > case $name in
              > > foo)
              > > echo this
              > > ;;
              > > bar)
              > > echo that
              > > ;;
              > > esac
              > >
              > >Does anyone have a fix for this?
              >
              > You could change global/indent/sh.vim to subtract an indent when a case is
              > defined. This would involve something like setting g:sh_case when 'case' is
              > encountered, and unsetting it when 'esac' is encountered; then reducing the
              > indent for lines ending in ')' iff g:sh_case is set.
              >
              > Perhaps someone has a better solution?

              I'm not very familiar with indent scripts, but I thought about
              tinkering with this one. The problem I had was distinguishing case
              labels (actually 'patterns') from other instances of closing
              parentheses on a line. I also discovered just now that the opening
              parenthesis is optional, although I have never seen it used.

              Gary

              --
              Gary Johnson | Agilent Technologies
              garyjohn@... | Wireless Division
              | Spokane, Washington, USA
            • Keith Roberts
              ... That s why I suggested setting/unsetting a global variable, so you would know that you are inside a case statement. Since there is no syntax file for
              Message 6 of 10 , Nov 5, 2003
                >-----Original Message-----
                >From: Gary Johnson [mailto:garyjohn@...]
                >Sent: Wednesday, November 05, 2003 11:33 AM
                >To: vim@...
                >Subject: Re: Formatting bash scripts
                >
                >On 2003-11-05, Keith Roberts <kroberts@...> wrote:
                >> >-----Original Message-----
                >> >From: Gary Johnson [mailto:garyjohn@...]
                >> >Sent: Wednesday, November 05, 2003 10:45 AM
                >> >To: vim@...
                >> >Subject: Re: Formatting bash scripts
                >> >
                >> >On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
                >> >> Hi,
                >> >> Is there a tool for setting the right indentation
                >> >> formatting for bash scripts?
                >> >
                >> >You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
                >> >to do pretty well except for case labels. That is, it formats a
                >> >case command as
                >> >
                >> > case $name in
                >> > foo)
                >> > echo this
                >> > ;;
                >> > bar)
                >> > echo that
                >> > ;;
                >> > esac
                >> >
                >> >instead of as
                >> >
                >> > case $name in
                >> > foo)
                >> > echo this
                >> > ;;
                >> > bar)
                >> > echo that
                >> > ;;
                >> > esac
                >> >
                >> >Does anyone have a fix for this?
                >>
                >> You could change global/indent/sh.vim to subtract an indent when a case
                >is
                >> defined. This would involve something like setting g:sh_case when 'case'
                >is
                >> encountered, and unsetting it when 'esac' is encountered; then reducing
                >the
                >> indent for lines ending in ')' iff g:sh_case is set.
                >>
                >> Perhaps someone has a better solution?
                >
                >I'm not very familiar with indent scripts, but I thought about
                >tinkering with this one. The problem I had was distinguishing case
                >labels (actually 'patterns') from other instances of closing
                >parentheses on a line. I also discovered just now that the opening
                >parenthesis is optional, although I have never seen it used.


                That's why I suggested setting/unsetting a global variable, so you would
                know that you are "inside" a case statement. Since there is no syntax file
                for shell scripts, you can't use SynID() and SynIDattr() for this purpose.
                One would presume that a line ending with ')' which either starts with '('
                or has one more ')' than '(' would likely be a case definition.
              • Russell Shaw
                ... Hi, I meant a beautifier thing to neaten up a large script with inconsistant indents. If you can get the indents right, then you can set folds using the
                Message 7 of 10 , Nov 5, 2003
                  Gary Johnson wrote:
                  > On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
                  >
                  >>Hi,
                  >>Is there a tool for setting the right indentation
                  >>formatting for bash scripts?
                  >
                  > You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
                  > to do pretty well except for case labels. That is, it formats a
                  > case command as...

                  Hi,
                  I meant a beautifier thing to neaten up a large script with
                  inconsistant indents. If you can get the indents right, then
                  you can set folds using the indents which makes debugging large
                  shell scripts much easier.

                  If you want to set the indents while entering bash code, then
                  see 30.3-30.4 of help.
                • John Aldridge
                  ... Is the = not working for you (with the indent/sh.vim)? As in: 1G=G
                  Message 8 of 10 , Nov 5, 2003
                    At 20:49 11-05-2003, Russell Shaw wrote:

                    >Gary Johnson wrote:
                    >>On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
                    >>
                    >>>Hi,
                    >>>Is there a tool for setting the right indentation
                    >>>formatting for bash scripts?
                    >>You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
                    >>to do pretty well except for case labels. That is, it formats a
                    >>case command as...
                    >
                    >Hi,
                    >I meant a beautifier thing to neaten up a large script with
                    >inconsistant indents. If you can get the indents right, then
                    >you can set folds using the indents which makes debugging large
                    >shell scripts much easier.
                    >
                    >If you want to set the indents while entering bash code, then
                    >see 30.3-30.4 of help.

                    Is the '=' not working for you (with the indent/sh.vim)? As in:

                    1G=G
                  • Russell Shaw
                    ... Equalprg works on C, but is there something for bash scripts?
                    Message 9 of 10 , Nov 5, 2003
                      John Aldridge wrote:
                      > At 20:49 11-05-2003, Russell Shaw wrote:
                      >
                      >> Gary Johnson wrote:
                      >>
                      >>> On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
                      >>>
                      >>>> Hi,
                      >>>> Is there a tool for setting the right indentation
                      >>>> formatting for bash scripts?
                      >>>
                      >>> You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
                      >>> to do pretty well except for case labels. That is, it formats a
                      >>> case command as...
                      >>
                      >>
                      >> Hi,
                      >> I meant a beautifier thing to neaten up a large script with
                      >> inconsistant indents. If you can get the indents right, then
                      >> you can set folds using the indents which makes debugging large
                      >> shell scripts much easier.
                      >>
                      >> If you want to set the indents while entering bash code, then
                      >> see 30.3-30.4 of help.
                      >
                      > Is the '=' not working for you (with the indent/sh.vim)? As in:
                      >
                      > 1G=G

                      Equalprg works on C, but is there something for bash scripts?
                    • John Aldridge
                      ... I ve mostly been using gVim 6.2 in Windows, and I don t remember trying this on a Linux or Cygwin version of Vim. If equalprg is left empty, then Vim does
                      Message 10 of 10 , Nov 5, 2003
                        At 23:20 11-05-2003, Russell Shaw wrote:

                        >John Aldridge wrote:
                        >>At 20:49 11-05-2003, Russell Shaw wrote:
                        >>
                        >>>Gary Johnson wrote:
                        >>>
                        >>>>On 2003-11-05, Russell Shaw <rjshaw@...> wrote:
                        >>>>
                        >>>>>Hi,
                        >>>>>Is there a tool for setting the right indentation
                        >>>>>formatting for bash scripts?
                        >>>>
                        >>>>You mean something other than $VIMRUNTIME/indent/sh.vim? It seems
                        >>>>to do pretty well except for case labels. That is, it formats a
                        >>>>case command as...
                        >>>
                        >>>
                        >>>Hi,
                        >>>I meant a beautifier thing to neaten up a large script with
                        >>>inconsistant indents. If you can get the indents right, then
                        >>>you can set folds using the indents which makes debugging large
                        >>>shell scripts much easier.
                        >>>
                        >>>If you want to set the indents while entering bash code, then
                        >>>see 30.3-30.4 of help.
                        >>Is the '=' not working for you (with the indent/sh.vim)? As in:
                        >> 1G=G
                        >
                        >Equalprg works on C, but is there something for bash scripts?

                        I've mostly been using gVim 6.2 in Windows, and I don't remember
                        trying this on a Linux or Cygwin version of Vim. If equalprg is left
                        empty, then Vim does what it can without an external program. That
                        means that Vim uses the indent/sh.vim or whatever indent file
                        applies. As mentioned earlier, bash case statements don't come out
                        all the nicely, but the rest seems to work quite well. I also get a
                        lot of use out of this on borrowed HTML files which are often badly
                        indented. The advantage of the '=' key is that you get to set your
                        shiftwidth and expandtab as you prefer. Of course, you can also
                        alter the indent file to taste.
                      Your message has been successfully submitted and would be delivered to recipients shortly.