21 votes

OpenGL bindings for Bash

13 comments

  1. [11]
    hungariantoast
    Link
    I'll fuckin do it again
    14 votes
    1. [6]
      goose
      (edited )
      Link Parent
      Your bash++ post inspired me to whip up a fun little one liner. I say, with enough semicolons, any bash script can be a one line bash script! May I present, a bash one line script that will turn...

      Your bash++ post inspired me to whip up a fun little one liner.

      If you are writing a script that is more than 100 lines long, or that uses non-straightforward control flow logic, you should rewrite it in a more structured language now.

      I say, with enough semicolons, any bash script can be a one line bash script! May I present, a bash one line script that will turn any other bash script into a one line script:

      while IFS= read -r line; do while [[ "${line:0:1}" =~ ($'\t'| ) ]]; do line="${line:1}"; done; if [[ "${line:0:1}" == "#" || -z "${line}" ]]; then continue; fi; if [[ "$line" =~ [^\\#][[:space:]]+# ]]; then line="${line% #*}"; fi; if [[ -n "${line}" ]]; then [[ "$line" =~ \b(do|then)$ ]] && output+="$line " || output+="$line; "; fi; done < "${1}"; output="${output//;;/;}"; echo "${output#;}"
      
      12 votes
      1. [2]
        priw8
        Link Parent
        Did you write it in 1 line originally, or in multiple lines and then run it on its own code to make it single line?

        Did you write it in 1 line originally, or in multiple lines and then run it on its own code to make it single line?

        6 votes
        1. goose
          Link Parent
          Wrote it in standard markdown to make sure it worked, then manually combined it to a single line because I have a smooth brain and didn't think to use it on itself. The readable/original: while...

          Wrote it in standard markdown to make sure it worked, then manually combined it to a single line because I have a smooth brain and didn't think to use it on itself.

          The readable/original:

          while IFS= read -r line; do
              # Strip leading tabs and white space
              while [[ "${line:0:1}" =~ ($'\t'| ) ]]; do
                  line="${line:1}"
              done
              # If it's a comment or blank line, skip it
              if [[ "${line:0:1}" == "#" || -z "${line}" ]]; then
                  continue
              fi
              # If it has a trailing comment, remove the trailing comment
              if [[ "$line" =~ [^\\#][[:space:]]+# ]]; then
                  line="${line% #*}"
              fi
              # If we still do not have a blank line, combine the output
              if [[ -n "${line}" ]]; then
                  [[ "$line" =~ \b(do|then)$ ]] && output+="$line " || output+="$line; "
              fi
          done < "${1}"
          # Remove redundant semicolons
          output="${output//;;/;}"
          # Trim any accidental leading semicolons
          echo "${output#;}
          
          4 votes
      2. [3]
        zestier
        Link Parent
        Sadly this isn't ready for production. Heredocs cause an invalid output file.

        Sadly this isn't ready for production. Heredocs cause an invalid output file.

        3 votes
        1. [2]
          goose
          Link Parent
          Never much cared for or used heredoc's myself, so didn't account for them. I guess I should say, turn most other bash scripts into a one line script.

          Never much cared for or used heredoc's myself, so didn't account for them. I guess I should say, turn most other bash scripts into a one line script.

          4 votes
          1. zestier
            Link Parent
            Unfortunately upon reread I'm noting that my comment completely lacks the joke-y tone it should've. I do use heredocs on occasion, usually for stuff like embedding a small config file where I only...

            Unfortunately upon reread I'm noting that my comment completely lacks the joke-y tone it should've. I do use heredocs on occasion, usually for stuff like embedding a small config file where I only have a single entry point such as putting a systemd service config into an EC2 userdata script, which just made me wonder what funny behaviors it may have if fed one. I was expecting it to fail, but what I wasn't expecting and was a bit amused by was that the EOF string at the end of the heredoc mysteriously vanished.

            3 votes
    2. donn
      Link Parent
      This is a good bit, by all means never stop

      This is a good bit, by all means never stop

      2 votes
    3. tobii
      Link Parent
      Disgusting, thanks for posting!

      Disgusting, thanks for posting!

      2 votes
    4. tauon
      Link Parent
      Where do you keep finding these?! It’s all interesting, and (unfortunately) still about Bash all the same. 😭

      Where do you keep finding these?!

      It’s all interesting, and (unfortunately) still about Bash all the same. 😭

      1 vote
  2. first-must-burn
    Link
    If this were IRC, this is where you would /nick hungarianbash Keep up the good work.

    If this were IRC, this is where you would
    /nick hungarianbash

    Keep up the good work.

    4 votes