All Projects → witchard → Mog

witchard / Mog

Licence: mit
A different take on the UNIX tool cat

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Mog

Fcat
A 3x faster implementation of cat, using splice
Stars: ✭ 196 (+216.13%)
Mutual labels:  cat, unix
colocat
Fegeya Colocat, Colorized 'cat' implementation. Written in C++17.
Stars: ✭ 14 (-77.42%)
Mutual labels:  cat, unix
splinter
Simple pattern-based linter 🐀
Stars: ✭ 31 (-50%)
Mutual labels:  unix, regex
Regex Builder
Write regular expressions in pure Java
Stars: ✭ 50 (-19.35%)
Mutual labels:  regex
Gpg Encrypt
Use GPG to encrypt a file using our best settings
Stars: ✭ 53 (-14.52%)
Mutual labels:  unix
Skalibs
The skarnet.org C system programming library
Stars: ✭ 58 (-6.45%)
Mutual labels:  unix
Unixagent
This is the OCS unified agent for Unix operating systems
Stars: ✭ 61 (-1.61%)
Mutual labels:  unix
Luneta
command-line fuzzy finder
Stars: ✭ 49 (-20.97%)
Mutual labels:  unix
Shx
Portable Shell Commands for Node
Stars: ✭ 1,111 (+1691.94%)
Mutual labels:  unix
Parsrs
CSV, JSON, XML text parsers and generators written in pure POSIX shellscript
Stars: ✭ 56 (-9.68%)
Mutual labels:  unix
Ore
An R interface to the Onigmo regular expression library
Stars: ✭ 54 (-12.9%)
Mutual labels:  regex
Regexr
For composing regular expressions without the need for double-escaping inside strings.
Stars: ✭ 53 (-14.52%)
Mutual labels:  regex
Applied Text Mining In Python
Repo for Applied Text Mining in Python (coursera) by University of Michigan
Stars: ✭ 59 (-4.84%)
Mutual labels:  regex
Xsuspender
👀 💻 💤 🔋 Save battery by auto-suspending unfocused X11 applications.
Stars: ✭ 53 (-14.52%)
Mutual labels:  unix
Zile
Extract API keys from file or url using by magic of python and regex.
Stars: ✭ 61 (-1.61%)
Mutual labels:  regex
Painless
Painless parameter handling for easy exploration
Stars: ✭ 51 (-17.74%)
Mutual labels:  unix
Angel Ps1
Your fancy shell prompt fed by your guardian angel
Stars: ✭ 60 (-3.23%)
Mutual labels:  unix
Cmd
A simple package to execute shell commands on linux, windows and osx
Stars: ✭ 56 (-9.68%)
Mutual labels:  unix
Ctregex.zig
Compile time regular expressions in zig
Stars: ✭ 55 (-11.29%)
Mutual labels:  regex
Regex In Python
A comprehensive guide for learning regular expressions using Python
Stars: ✭ 58 (-6.45%)
Mutual labels:  regex

mog

A different take on the UNIX tool cat.

example

Travis license PyPI PyPI AUR

What is this?

The 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:

  • Syntax highlight scripts
  • Print a hex dump of binary files
  • Show details of image files
  • Perform objdump on executables
  • List a directory

Installation

The simplest way is to install via pip: [sudo] pip install mog.

Required dependencies are the file command (e.g. sudo apt install file).

If 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.

@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&stype=name&sektion=sysutils.

For the latest development version:

  • [sudo] pip install git+https://github.com/witchard/mog
  • Or clone this repository and then run [sudo] python ./setup.py install

Default Config

If 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)

  • File extension is recognised by pygments - Format with pygmentize (http://pygments.org/)
  • File mime type is recognisd by pygments - Format with pygmentize (http://pygments.org/)
  • File type is ELF - Parse with objdump -ft
  • File is not a file (i.e. directory / symlink / fifo) - List it using ls -lh
  • File is of a video or image mime type - Summarise it with mediainfo (http://mediainfo.sourceforge.net)
  • File is a PDF document - Print it as text using pdftotext (https://poppler.freedesktop.org/)
  • File is a tar archive - List contents of tar using tar --list
  • File extension is .deb - Show information using dpkg -I
  • File extension is .rpm - Show information using rpm -qip
  • File extension is .csv - Format it using column -xt -s,
  • File extension is .tsv - Format it using column -xt
  • File contains ASCII text - Print using cat
  • Anything else - Assumed to be binary, print using xxd

How does it work?

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.

Matches

Currently the following match commands are supported:

  • name=<regex> - Check if the file name matches the regex
  • file=<regex> - Check if the output of file matches the regex
  • file_mime=<regex> - Check if the output of file --mime matches the regex
  • pygmentize=<regex> - Check if the output of pygmentize -N matches the regex
  • pygmentsmime=<regex> - Check if the pygments lexer for the files mimetype matches the regex. Always failes when there is no pygments lexer for the specified mimetype

Note, one can specify invert_match, you can use this to cause a match when the regex does not match.

Actions

The following actions are supported:

  • arg=<program> - Pass the file name as an argument to the program
  • argreplace=<program> - Replace %F in <program> with the filename. Replace %N (where N is an integer) in <program> with matching capture group from match regex. Execute the result.

Config file format

The config file is an ini style format defined as follows:

[settings]
showname=yes
showsection=no
viewinless=no
toponly=no
toplines=10
followsymlinks=no
recursive=no

[name-of-match-action-1]
match=arg
action=arg
invert_match=boolean

[name-of-match-action-2]
match=arg
action=arg
invert_match=boolean

The settings section may contain the following:

  • showname - default: True. Show the name of each file before performing the action.
  • showsection - default: False. Show config file section where match occurred next to file name. showname must be True for this to work.
  • viewinless - default: False. Output everything in a pager (less -S).
  • toponly - default: False. Output only the top few lines of each file.
  • toplines - default: 10. Number of lines to output in toponly mode.
  • followsymlinks - default: False. Follow symbolic links when processing files.
  • recursive - default: False. Recurse into directories to process the files within them.

The 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.

Matches and actions will be processed in the order found in the file.

It 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].