Package: rifleman
riflemanAn extendible dispatcher to lint/format code, based onrifleThis lets you run one command over lots of files/directories which could be in different languages - it classifies them by inspecting the mime type, extension, name or shebang, and then runs a command on those files.This heavily simplifies and modifies the rifle config file format; including a condition to help check the 'shebang' value for scripts.Seeconfig/format.conffor the default configuration file, I recommend you customize it to include the commands you use.By default, I've included lots of theformaters/linters I use, an excerpt:# htmlext x?html?, has prettier = prettier -w "$@"# web technologies, handled by prettierext vue|yaml|json|graphql|tsx?|jsx?|s?css|less|md, has prettier = prettier -w "$@"# golangext go, has go = go fmt "$@"# pythonext py, has black = black "$@"mime text/x-script.python, has black = black "$@"shebang python(2|3)?, has black = black "$@"# shell scriptshebang zsh|bash, has shfmt = shfmt -w "$@"shebang \/bin\/sh, has shfmt = shfmt -w "$@"ext sh|(ba|z)sh, has shfmt = shfmt -w "$@"mime text/x-shellscript, has shfmt = shfmt -w "$@"Usedemacs-format-all-the-codeas reference.Though the example is here is for code, similar to rifle, this could be used to dispatch against any file/mime type. I've includedimage.conf, which takes any files as inputs, matches theimage/png|jpeg|gifmimetypes, and runsoptipng/jpegtran/gifsicleto optimize those files to reduce their file size. That could be run likefd -X rifleman -a image, to optimize all images in any subdirectores.Feel free to PR additional formatters!InstallationRequirespython3.7+To install with pip, run:pip install riflemanUsageUsage: rifleman [-] [-ljpcah] [files]...

Pass '-' to read filenames from STDIN, separated by newlines

Options:
  -h, --help      show this help message and exit
  -l              list actions for files
  -j              list actions for files as JSON
  -m              list computed mime type for each file
  -p              prompt before running each command
  -c CONFIG_FILE  read config from specified file instead of default
  -a ACTION       name of configuration file in config directory to use
                  (lint|format|image)This doesn't offer a way to discover/search for files, because so many tools already exist to do that.With shell globbing:rifleman*.md./project/*.pyTo run this against all files in a git-tracked directory:gitls-files|rifleman-You canfind(with the-execflag), or the friendlierfd, to run against all files in the directory recursively:fd-XriflemanThe-jand-lflags print what commands which would be used on each file instead of running the command.The-cand-afiles are used to determine which config file to use, completely altering the functionality of this.By default, it uses theformat.conffile in the${XDG_CONFIG_HOME:-${HOME}/.config}/riflemandirectory.-ais a shorthand; specifying-a lintlooks for a file in the configuration directory calledlint.confWhen this is first run, it will try to download the configuration files into the corresponding directories.If you're trying to debug which mimetype to use for a particular file, you can use the-mflag, to dump the mimetyperiflemandetermines.$gitls-files|shuf-n3|rifleman--m
pytest.ini:text/plain
rifleman/py.typed:inode/x-empty
rifleman/__main__.py:text/x-pythonFor reference, that works by checking the known user-defined mimetypes at~/.mime.types, using the builtinmimetypespython module. If that fails to find a mimetype, it runs the command:file --mime-type -Lb <file>.Example$rifleman*.md$(fd\.py$)Running:/bin/sh-cset--'README.md';prettier-w"$@"README.md88ms
Running:/bin/sh-cset--'rifleman/__init__.py''rifleman/__main__.py''setup.py''tests/test_rifleman.py';black"$@"Alldone!✨🍰✨4filesleftunchanged.Testsgitclone'https://github.com/seanbreckenridge/rifleman'cd./rifleman
pipinstall'.[testing]'mypy./rifleman
pytest