{"id":16510733,"url":"https://github.com/witchard/mog","last_synced_at":"2025-03-16T18:32:36.933Z","repository":{"id":57442767,"uuid":"81683246","full_name":"witchard/mog","owner":"witchard","description":"A different take on the UNIX tool cat","archived":false,"fork":false,"pushed_at":"2019-09-04T06:16:49.000Z","size":100,"stargazers_count":65,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T12:20:04.450Z","etag":null,"topics":["cat","cmdline","mime-types","mog","pygments","python","regex","shell","unix"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/witchard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-11T21:23:40.000Z","updated_at":"2024-05-19T12:23:31.000Z","dependencies_parsed_at":"2022-09-26T17:21:21.025Z","dependency_job_id":null,"html_url":"https://github.com/witchard/mog","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/witchard%2Fmog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/witchard%2Fmog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/witchard%2Fmog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/witchard%2Fmog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/witchard","download_url":"https://codeload.github.com/witchard/mog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826780,"owners_count":20354220,"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":["cat","cmdline","mime-types","mog","pygments","python","regex","shell","unix"],"created_at":"2024-10-11T15:56:40.129Z","updated_at":"2025-03-16T18:32:32.505Z","avatar_url":"https://github.com/witchard.png","language":"Python","readme":"# `mog`\n\nA different take on the UNIX tool `cat`.\n\n![example](mog.gif)\n\n[![Travis](https://img.shields.io/travis/witchard/mog.svg)](https://travis-ci.org/witchard/mog)\n[![license](https://img.shields.io/github/license/witchard/mog.svg)](https://witchard.mit-license.org)\n[![PyPI](https://img.shields.io/pypi/pyversions/mog.svg)](https://pypi.python.org/pypi/mog)\n[![PyPI](https://img.shields.io/pypi/v/mog.svg)](https://pypi.python.org/pypi/mog)\n[![AUR](https://img.shields.io/aur/version/mog-git.svg)](https://aur.archlinux.org/packages/mog-git/)\n\n## What is this?\n\nThe man page for `cat` says that it can: concatenate files and print on the standard output. Often (at least for me) its main use is for the latter... `mog` tries to help you \"print on the standard output\" in a more intelligent way. For example, it can be configured to:\n\n* Syntax highlight scripts\n* Print a hex dump of binary files\n* Show details of image files\n* Perform `objdump` on executables\n* List a directory\n\n## Installation\n\nThe simplest way is to install via pip: `[sudo] pip install mog`.\n\nRequired dependencies are the `file` command (e.g. `sudo apt install file`).\n\nIf you plan on using the default configuration file, then you will also want `poppler-utils`, `binutils` and `mediainfo` installed (e.g. `sudo apt install poppler-utils binutils mediainfo` on a debian based machine). You'll also need `pygmentize` - this should be installed automatically with `pip install mog`, but some users have reported this not to be the case (e.g. issue #18) - if this happens a separate `pip install pygments` will hopefully do the trick.\n\n@gregf has kindly provided an Arch Linux package: https://aur.archlinux.org/packages/mog-git/. There is also a FreeBSD port: https://www.freebsd.org/cgi/ports.cgi?query=%5Emog\u0026stype=name\u0026sektion=sysutils.\n\nFor the latest development version:\n* `[sudo] pip install git+https://github.com/witchard/mog`\n* Or clone this repository and then run `[sudo] python ./setup.py install`\n\n## Default Config\n\nIf you don't give `mog` a configuration file, it will use the defaults. Here is what you will get (prioritised in the order below - i.e. the first thing to match is done)\n\n* File extension is recognised by pygments - Format with `pygmentize` (http://pygments.org/)\n* File mime type is recognisd by pygments - Format with `pygmentize` (http://pygments.org/)\n* File type is ELF - Parse with `objdump -ft`\n* File is not a file (i.e. directory / symlink / fifo) - List it using `ls -lh`\n* File is of a video or image mime type - Summarise it with `mediainfo` (http://mediainfo.sourceforge.net)\n* File is a PDF document - Print it as text using `pdftotext` (https://poppler.freedesktop.org/)\n* File is a tar archive - List contents of tar using `tar --list`\n* File extension is .deb - Show information using `dpkg -I`\n* File extension is .rpm - Show information using `rpm -qip`\n* File extension is .csv - Format it using `column -xt -s,`\n* File extension is .tsv - Format it using `column -xt`\n* File contains ASCII text - Print using `cat`\n* Anything else - Assumed to be binary, print using `xxd`\n\n## How does it work?\n\n`mog` reads the `$HOME/.mogrc` config file which describes a series of operations it can do in an ordered manner. The config file can be overridden with the `--config` argument. Each operation has a match command and an action command. For each file you give to `mog` it will test each match command in turn, when one matches it will perform the action. A reasonably useful config file is generated when you first run it.\n\n### Matches\n\nCurrently the following match commands are supported:\n\n* `name=\u003cregex\u003e` - Check if the file name matches the regex\n* `file=\u003cregex\u003e` - Check if the output of `file` matches the regex\n* `file_mime=\u003cregex\u003e` - Check if the output of `file --mime` matches the regex\n* `pygmentize=\u003cregex\u003e` - Check if the output of `pygmentize -N` matches the regex\n* `pygmentsmime=\u003cregex\u003e` - Check if the pygments lexer for the files mimetype matches the regex. Always failes when there is no pygments lexer for the specified mimetype\n\nNote, one can specify `invert_match`, you can use this to cause a match when the regex does not match.\n\n### Actions\n\nThe following actions are supported:\n\n* `arg=\u003cprogram\u003e` - Pass the file name as an argument to the program\n* `argreplace=\u003cprogram\u003e` - Replace %F in `\u003cprogram\u003e` with the filename. Replace %N (where N is an integer) in `\u003cprogram\u003e` with matching capture group from match regex. Execute the result.\n\n### Config file format\n\nThe config file is an ini style format defined as follows:\n\n```ini\n[settings]\nshowname=yes\nshowsection=no\nviewinless=no\ntoponly=no\ntoplines=10\nfollowsymlinks=no\nrecursive=no\n\n[name-of-match-action-1]\nmatch=arg\naction=arg\ninvert_match=boolean\n\n[name-of-match-action-2]\nmatch=arg\naction=arg\ninvert_match=boolean\n```\n\nThe `settings` section may contain the following:\n\n* `showname` - default: `True`. Show the name of each file before performing the action.\n* `showsection` - default: `False`. Show config file section where match occurred next to file name. `showname` must be `True` for this to work.\n* `viewinless` - default: `False`. Output everything in a pager (`less -S`).\n* `toponly` - default: `False`. Output only the top few lines of each file.\n* `toplines` - default: `10`. Number of lines to output in `toponly` mode.\n* `followsymlinks` - default: `False`. Follow symbolic links when processing files.\n* `recursive` - default: `False`. Recurse into directories to process the files within them.\n\nThe `invert_match` value is optional and will cause the match to be inverted - i.e. you can use this to cause a match when the regex does not match.\n\nMatches and actions will be processed in the order found in the file.\n\nIt should be noted that `mog` uses the name of the script to determine what config file to read. So for example one can `ln -s mog feline` and then it would use the `$HOME/.felinerc` as the config file. This means you can have multiple configurations for different names.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwitchard%2Fmog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwitchard%2Fmog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwitchard%2Fmog/lists"}