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

WIP - Improvements to bash code w/ test suite #2810

Draft
wants to merge 23 commits into
base: github
Choose a base branch
from

Commits on Nov 4, 2023

  1. Use /usr/bin/env style shebangs for bash

    This style is preferred as it makes it possible to use more modern bash
    on systems where /bin/bash is ancient. (looking at you, macos)
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    fedb1a8 View commit details
    Browse the repository at this point in the history
  2. Set strict Bash options

    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    81b2c30 View commit details
    Browse the repository at this point in the history
  3. Unset -u for now; too strict

    `set -u` guards against using unassinged vars but most of this code
    would break.
    We'll address this later on a file by file basis, with tests.
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    c37f4cc View commit details
    Browse the repository at this point in the history
  4. Add a test suite and make test support

    The first test is to apply shellcheck linting to the bash code.
    
    The following commits will address the linting errors found here.
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    87e9628 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    56763f3 View commit details
    Browse the repository at this point in the history
  6. Alway use [[ ... ]] conditionals

    The `[` is just a command with args and expects/ignores the `]` final arg.
    
    That means you need to be very concerned about what's inside `[ ... ]`.
    
    The `[[ ... ]]` is Bash syntax and everything inside is handled as
    syntax.
    That means you don't need to quotes variable expansions.
    Bash knows what you want and does it properly.
    
    Some related changes were made in this context:
    
    * [[ $foo ]] same as [[ -n $foo ]] same as [[ $foo != "" ]]
    * [[ -z $foo ]] same as [[ $foo == "" ]]
    * Prefer == over = for string equality
    * Prefer -eq over == for numeric equality
    * $* means all aregs expanded into 1 string
    * Words without meta chars are strings in Bash. No need to quote them.
    
    Note: the RHS of a == or != op must be quoted if it is a variable
    expansion, but shellcheck would complain if you didn't quote it.
    
    All the files are still shellcheck compliant.
    
    Very confident of this commit.
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    324d409 View commit details
    Browse the repository at this point in the history
  7. First attempt at using 'set -u'

    (in lein and bump)
    
    Added a couple tests but need more rigorous testing to make sure
    everything works without error.
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    a7f2178 View commit details
    Browse the repository at this point in the history
  8. Remove useless quotes from assignment statements

    In Bash `foo=$bar` or `foo=$( bar $baz )` is smart about parsing and
    doesn't blindly expand vars with spaces or meta chars.
    
    Arguments with expansions, on the other hand, need quoting.
    
    Preferred to only use double quotes when expansions are present.
    
    Else use single quotes.
    ingydotnet committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    7919907 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    eda4479 View commit details
    Browse the repository at this point in the history

Commits on Nov 5, 2023

  1. Add handy msg, err, and die functions

    Makes code cleaner and easier to read.
    Makes it obvious when things are going to stdout or stderr.
    
    Note: `printf` repeats its pattern until all args are consumed, so the
    `msg` function will print a line for each arg.
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    004581f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    82c3ce1 View commit details
    Browse the repository at this point in the history
  3. Improve cd usage

    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    5b20489 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1d4b676 View commit details
    Browse the repository at this point in the history
  5. Change function_names to function-names

    Unlike vars, functions in bash can contain most of the chars found in
    file names, which makes sense as a command can either be a function or a
    PATH command.
    
    A Lisper should like it.
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    8841944 View commit details
    Browse the repository at this point in the history
  6. Wrap long lines

    Note: you can end a line with && || or | and it will continue without
    using \.
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    9a96fae View commit details
    Browse the repository at this point in the history
  7. A couple adjustments

    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    4550cb0 View commit details
    Browse the repository at this point in the history
  8. Change which to 'command -v'

    command is a bash builtin
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    2b599dc View commit details
    Browse the repository at this point in the history
  9. Minor fixups

    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    622ce2d View commit details
    Browse the repository at this point in the history
  10. Remove \" escapes

    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    139cb68 View commit details
    Browse the repository at this point in the history
  11. Replace '> ... 2>&1' with '&> ...'

    Syntax available since bash 3.2
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    6a804ff View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    044dbf7 View commit details
    Browse the repository at this point in the history
  13. Fix a likely typo

    $(dirname "$SCRIPT"$) makes not sense to me.
    
    Surprised it's not a bash syntax error though
    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    f6f0c58 View commit details
    Browse the repository at this point in the history
  14. Wrap a couple long ones

    ingydotnet committed Nov 5, 2023
    Configuration menu
    Copy the full SHA
    906d616 View commit details
    Browse the repository at this point in the history