Skip to content
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

Suggestion: cleaner debug code #13

Closed
alphapapa opened this issue May 17, 2017 · 4 comments
Closed

Suggestion: cleaner debug code #13

alphapapa opened this issue May 17, 2017 · 4 comments

Comments

@alphapapa
Copy link
Contributor

Hi again,

Just a suggestion you might want to consider. There's a really cool technique for Bash scripts, which I've seen called a "collapsing function." It's especially useful for optional debug output. Here's an example:

function debug {
    # A collapsing function. Cool.
    if [[ $debug ]]
    then
        function debug {
            echo -e "${COLOR_YELLOW}DEBUG: ${@}${COLOR_OFF}" >&2
        }
        debug "$@"
    else
        function debug {
            true
        }
    fi
}

Then to send debug output, you just do:

debug "Something"

instead of having to do:

if [[ $debug ]]
then
  echo something >&2
fi

And by redefining or "collapsing" the function, it avoids the tests when debugging is disabled (though I doubt it matters in a shell script).

@kaushalmodi
Copy link
Owner

This is awesome. Thanks! I didn't know this existed. Would you like to work on a PR for this?

@alphapapa
Copy link
Contributor Author

Ok, I pushed a branch here: https://github.com/alphapapa/eless/tree/collapsing-debug

I tried to build it according to the instructions, but unfortunately I have several Org-export variables set differently, and this resulted in a lot of whitespace noise and other minor differences in the exported files. It doesn't seem worth the time it would take for me to figure out which variables to change and what to change them to to make the output the same as you get, so I haven't committed the exported changes, just the raw changes to the org file.

@kaushalmodi
Copy link
Owner

(It's a GitHub "feature".. The commit message had "Fixes Issue#", so it auto-closed this issue.)

Thanks for that commit! It did get rid of a lot of clutter from eless. I am now using this in all my future bash scripts (and past) :)

I tried to build it according to the instructions, but unfortunately I have several Org-export variables set differently, and this resulted in a lot of whitespace noise and other minor differences in the exported files.

Ah, that sucks.. I will figure out how to resolve this so that org based project collaboration becomes easier. May be I just need to have a look at your config for now to see which org-* vars are set differently.

It doesn't seem worth the time it would take for me to figure out which variables to change and what to change them to to make the output the same as you get, so I haven't committed the exported changes, just the raw changes to the org file.

No problem. Thanks for that commit!

@alphapapa
Copy link
Contributor Author

Cool, thanks for fixing it up. :)

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

2 participants