/cliview

cliview - Preview any file type directly in the shell with custom invocations

Primary LanguageGo

cliview

Cliview is a command-line tool that allows one to customize views for any type of file (eg: zip bundles, images, directories, etc.). Think of it like OSX's "QuickLook" feature for the terminal.

The inspiration for this tool comes from fzf's preview feature. One ought to be able to run fzf --preview="cliview {}" and be rewarded with powerful previews across a wide range of file types.

Demo

asciinema

Installation

See the releases page for binary releases.

Or go install github.com/kevin-cantwell/cliview@latest

Configuration

The flexibility of the tool is derived from its configuration file, which allows one to customize "viewers", which are mappings of file types to shell commands that generate output. For example, directories (inode/directory) can be mapped to tree or exa instead of ls (the default). Images or videos can be mapped to imgcat or timg to render a colorized visualization.

How files are classified into types can also be customized. By default, a file's mime-type and extension are used to determine which viewer command is executed.

By default the config file is written to $HOME/.config/cliview/config.yaml. Edit this file to customize commands to your liking:

# Classifiers are used to calculate file types.
# If multiple classifiers are configured, each will be evaluated
# in the order they are given. In this way, you can make a best-effort
# classification followed by a fallback method (eg: mime-type then file extension)
classifiers:
# MIME Type (eg: inode/symlink, video/quicktime, etc.)
- file -b --mime-type '{}'
# File extension with dot (eg: .zip, .txt, .java, etc.)
- filename='{}'; echo .${filename##*.}
# Viewers map classification patterns to a command that prints a useful view of that type.
# Multiple classification patterns may be specified for a single view command.
# Classification matches are evaluated in order (top to bottom, left to right) to determine which view is executed.
# Classification patterns may be glob expressions.
viewers:
inode/directory: ls -ltraR '{}'
inode/symlink: cliview "$(readlink -f '{}')"
inode/*: file -I '{}'
application/zip,.zip: zipinfo '{}'
.db,.sqlite: sqlite3 '{}' .tables | tr -s " " "\n" | xargs -I+ sqlite3 -cmd "select char(10) || '+:'" -cmd ".mode columns" -cmd "pragma table_info('+')" '{}'
application/gzip,.gz: tar -tf '{}'
text/plain: cat '{}''
'*': xxd '{}'

Usage

NAME:
   cliview - Preview any file type directly in the terminal.

USAGE:
   cliview [options] FILE

VERSION:
   0.1.0

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value, -c value  The config file to use. (default: "/Users/kevin-cantwell/.config/cliview/config.yml")
   --explain, -e             Print the configured view command without executing it.
   --help, -h                show help
   --version, -v             print the version