Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Last active October 30, 2021 23:05
Show Gist options
  • Save wbbradley/2ac8f0445d57c1aabba8ca6a7874cde3 to your computer and use it in GitHub Desktop.
Save wbbradley/2ac8f0445d57c1aabba8ca6a7874cde3 to your computer and use it in GitHub Desktop.
bootstrappy

bootstrappy

A bash script that will bootstrap any Python script.

Requirements

  • Uses Python3
  • The command is installed with the same package name as how it is invoked. For example: pip install cmakelint allows you to run cmakelint

Usage:

  • Copy bootstrappy anywhere on your system and chmod +x bootstrappy.
  • In a directoryin in your path, soft link to bootstrappy with the name of a tool you'd like to bootstrap. From the example earlier that might look like:
$ cd ~bin
$ ln -s /somewhere/bootstrappy cmakelint
# Now you should be able to just run the tool you've installed:
$ cmakelint
Collecting cmakelint
  Using cached cmakelint-1.4.1-py3-none-any.whl (12 kB)
Installing collected packages: cmakelint
Successfully installed cmakelint-1.4.1

Syntax: cmakelint.py [--version] [--config=file] [--filter=-x,+y] [--spaces=N]
                     [--quiet] [--linelength=digits]
        <file> [file] ...
    filter=-x,+y,...
      Specify a comma separated list of filters to apply

    spaces=N
      Indentation should be a multiple of N spaces

    config=file
      Use the given file for configuration. By default the file
      ~/.config/cmakelintrc, $XDG_CONFIG_DIR/cmakelintrc or ~/.cmakelintrc is
      used if it exists.  Use the value "None" to use no configuration file
      (./None for a file called literally None) Only the option "filter=" is
      currently supported in this file.

    quiet makes output quiet unless errors occurs
      Mainly used by automation tools when parsing huge amount of files.
      In those cases actual error might get lost in the pile of other stats
      prints.

      This argument is also handy for build system integration, so it's
      possible to add automated lint target to a project and invoke it
      via build system and have no pollution of terminals or IDE.

    linelength=digits
      This is the allowed line length for the project. The default value is
      80 characters.

      Examples:
        --linelength=120

    version
      Show the version number and end
FATAL ERROR: No files were specified!
#!/bin/bash
toolname="$(basename "$0")"
progname="bootstrappy-$toolname"
die() {
printf "\033[0;38;2;200;15;15m%s\033[0m: error: " "$progname" >&2
printf "%s" "$@" >&2
printf "\n" >&2
exit 1
}
envdir="$HOME/.bootstrappy/$toolname"
activate="$envdir/bin/activate"
if ! [[ -f "$activate" ]]; then
python3 -mvenv "$envdir" || die "unable to make a virtualenv [envdir=$envdir]"
# shellcheck disable=SC1090
. "$activate" || die "python env is not set up [envdir=$envdir]"
pip install "$toolname"
fi
# shellcheck disable=SC1090
. "$activate" || die "python env is not set up [envdir=$envdir]"
"$toolname" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment