mog
A different take on the UNIX tool cat
.
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:
objdump
on executablesThe 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
[sudo] python ./setup.py install
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)
pygmentize
(http://pygments.org/)pygmentize
(http://pygments.org/)objdump -ft
ls -lh
mediainfo
(http://mediainfo.sourceforge.net)pdftotext
(https://poppler.freedesktop.org/)tar --list
dpkg -I
rpm -qip
column -xt -s,
column -xt
cat
xxd
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.
Currently the following match commands are supported:
name=<regex>
- Check if the file name matches the regexfile=<regex>
- Check if the output of file
matches the regexfile_mime=<regex>
- Check if the output of file --mime
matches the regexpygmentize=<regex>
- Check if the output of pygmentize -N
matches the regexpygmentsmime=<regex>
- Check if the pygments lexer for the files mimetype matches the regex. Always failes when there is no pygments lexer for the specified mimetypeNote, one can specify invert_match
, you can use this to cause a match when the regex does not match.
The following actions are supported:
arg=<program>
- Pass the file name as an argument to the programargreplace=<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.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.