{"id":18136235,"url":"https://github.com/purarue/rifleman","last_synced_at":"2025-08-21T20:33:42.805Z","repository":{"id":57461998,"uuid":"307218639","full_name":"purarue/rifleman","owner":"purarue","description":"An extendible dispatcher to lint/format code, based on rifle","archived":false,"fork":false,"pushed_at":"2024-10-27T20:20:27.000Z","size":90,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-22T15:50:39.480Z","etag":null,"topics":["autoformat","file-launcher","linting"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/rifleman/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purarue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-26T00:05:52.000Z","updated_at":"2024-10-27T20:20:31.000Z","dependencies_parsed_at":"2024-11-01T14:41:25.404Z","dependency_job_id":"3e4fa3e4-7def-443e-bd69-02bbe6c3ad6c","html_url":"https://github.com/purarue/rifleman","commit_stats":{"total_commits":43,"total_committers":1,"mean_commits":43.0,"dds":0.0,"last_synced_commit":"e97fa5819f39c13c8465ffc59363d85618288044"},"previous_names":["seanbreckenridge/rifleman"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Frifleman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Frifleman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Frifleman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Frifleman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purarue","download_url":"https://codeload.github.com/purarue/rifleman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230532452,"owners_count":18240792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoformat","file-launcher","linting"],"created_at":"2024-11-01T14:41:13.378Z","updated_at":"2024-12-20T04:13:13.150Z","avatar_url":"https://github.com/purarue.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rifleman\n\n[![PyPi version](https://img.shields.io/pypi/v/rifleman.svg)](https://pypi.python.org/pypi/rifleman) [![Python 3.7|3.8|3.9](https://img.shields.io/pypi/pyversions/rifleman.svg)](https://pypi.python.org/pypi/rifleman) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nAn extendible dispatcher to lint/format code, based on [rifle](https://github.com/ranger/ranger)\n\nThis 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.\n\nThis heavily simplifies and modifies the rifle config file format; including a condition to help check the 'shebang' value for scripts.\n\nSee [config/format.conf](./config/format.conf) for the default configuration file, I recommend you customize it to include the commands you use.\n\nBy default, I've included lots of the `format`ers/`lint`ers I use, an excerpt:\n\n```yaml\n# html\next x?html?, has prettier = prettier -w \"$@\"\n# web technologies, handled by prettier\next vue|yaml|json|graphql|tsx?|jsx?|s?css|less|md, has prettier = prettier -w \"$@\"\n\n# golang\next go, has go = go fmt \"$@\"\n\n# python\next py, has black = black \"$@\"\nmime text/x-script.python, has black = black \"$@\"\nshebang python(2|3)?, has black = black \"$@\"\n\n# shell script\nshebang zsh|bash, has shfmt = shfmt -w \"$@\"\nshebang \\/bin\\/sh, has shfmt = shfmt -w \"$@\"\next sh|(ba|z)sh, has shfmt = shfmt -w \"$@\"\nmime text/x-shellscript, has shfmt = shfmt -w \"$@\"\n```\n\nUsed [emacs-format-all-the-code](https://github.com/lassik/emacs-format-all-the-code) as reference.\n\nThough the example is here is for code, similar to rifle, this could be used to dispatch against any file/mime type. I've included [image.conf](config/image.conf), which takes any files as inputs, matches the `image/png|jpeg|gif` mimetypes, and runs `optipng`/`jpegtran`/`gifsicle` to optimize those files to reduce their file size. That could be run like `fd -X rifleman -a image`, to optimize all images in any subdirectores.\n\nFeel free to PR additional formatters!\n\n## Installation\n\nRequires `python3.7+`\n\nTo install with pip, run:\n\n    pip install rifleman\n\n---\n\n## Usage\n\n```\nUsage: rifleman [-] [-ljpcah] [files]...\n\nPass '-' to read filenames from STDIN, separated by newlines\n\nOptions:\n  -h, --help      show this help message and exit\n  -l              list actions for files\n  -j              list actions for files as JSON\n  -m              list computed mime type for each file\n  -p              prompt before running each command\n  -c CONFIG_FILE  read config from specified file instead of default\n  -a ACTION       name of configuration file in config directory to use\n                  (lint|format|image)\n```\n\nThis doesn't offer a way to discover/search for files, because so many tools already exist to do that.\n\nWith shell globbing:\n\n```bash\nrifleman *.md ./project/*.py\n```\n\nTo run this against all files in a git-tracked directory:\n\n```bash\ngit ls-files | rifleman -\n```\n\nYou can `find` (with the `-exec` flag), or the friendlier [`fd`](https://github.com/sharkdp/fd), to run against all files in the directory recursively:\n\n```bash\nfd -X rifleman\n```\n\nThe `-j` and `-l` flags print what commands which would be used on each file instead of running the command.\n\nThe `-c` and `-a` files are used to determine which config file to use, completely altering the functionality of this.\n\nBy default, it uses the `format.conf` file in the `${XDG_CONFIG_HOME:-${HOME}/.config}/rifleman` directory. `-a` is a shorthand; specifying `-a lint` looks for a file in the configuration directory called `lint.conf`\n\nWhen this is first run, it will try to download the configuration files into the corresponding directories.\n\nIf you're trying to debug which mimetype to use for a particular file, you can use the `-m` flag, to dump the mimetype `rifleman` determines.\n\n```bash\n$ git ls-files | shuf -n 3 | rifleman - -m\npytest.ini:text/plain\nrifleman/py.typed:inode/x-empty\nrifleman/__main__.py:text/x-python\n```\n\nFor reference, that works by checking the known user-defined mimetypes at `~/.mime.types`, using the builtin [`mimetypes`](https://docs.python.org/3/library/mimetypes.html) python module. If that fails to find a mimetype, it runs the command: `file --mime-type -Lb \u003cfile\u003e`.\n\n### Example\n\n```bash\n$ rifleman *.md $(fd \\.py$)\nRunning: /bin/sh -c set -- 'README.md'; prettier -w \"$@\"\nREADME.md 88ms\nRunning: /bin/sh -c set -- 'rifleman/__init__.py' 'rifleman/__main__.py' 'setup.py' 'tests/test_rifleman.py'; black \"$@\"\nAll done! ✨ 🍰 ✨\n4 files left unchanged.\n```\n\n### Tests\n\n```bash\ngit clone 'https://github.com/purarue/rifleman'\ncd ./rifleman\npip install '.[testing]'\nmypy ./rifleman\npytest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Frifleman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurarue%2Frifleman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Frifleman/lists"}