Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9dae399
move fresh preview into place atomically with "mv"
foxharp Jan 3, 2025
0e73af1
accept either nsxiv or sxiv, and either convert or magick
foxharp Jan 3, 2025
2498269
restart viewer after user may have quit
foxharp Jan 3, 2025
f49f23c
don't force an initial position for the preview window.
foxharp Jan 3, 2025
be44d99
add debug tracing support
foxharp Jan 3, 2025
7729681
add more characters to the preview text
foxharp Jan 3, 2025
0523063
add the font name to the preview window text, and adjust window size
foxharp Jan 3, 2025
ac94aac
clean up the exit cleanup
foxharp Jan 3, 2025
3638672
preserve the fzf query string between selections
foxharp Jan 3, 2025
ef5a161
split out some initialization, for the command-line only invocations
foxharp Jan 3, 2025
22203bf
add support for feh image viewer
foxharp Jan 4, 2025
74decc8
mention alternate image viewers in the README
foxharp Jan 4, 2025
536dc82
handle fzf exit codes, to handle failed searches better
foxharp Feb 8, 2025
cd42560
turn off fzf coloring
foxharp Feb 8, 2025
ce6b5ef
add string of confusable digits to preview text
foxharp Feb 9, 2025
b10c014
give preview's header its own font size
foxharp Feb 10, 2025
fae11af
don't suppress SIGTSTP -- let things suspend naturally
foxharp Feb 10, 2025
3cf422d
extra newling on exit, to be sure we get a clean prompt
foxharp Feb 11, 2025
c0a468f
enable history, and make it a history of results, not queries
foxharp Feb 11, 2025
401e902
lots of option simplification, and code rearrangement
foxharp Feb 11, 2025
c00dd34
No real need for a Makefile for a shell script
foxharp Feb 12, 2025
77daec7
update copyright, add license text to script, so they stay together
foxharp Feb 12, 2025
4d4f1bc
tweaks to user config, and to make debug a little cleaner
foxharp Feb 12, 2025
162d3c4
new animated demo
foxharp Feb 12, 2025
cfd4128
revised README
foxharp Feb 12, 2025
1cd90f9
add download instructions
foxharp Feb 12, 2025
069c1f8
implemented auto-sizing of the preview window, and revise option proc…
foxharp Feb 13, 2025
c9f8418
updated usage in README
foxharp Feb 13, 2025
2f32db9
make history a little more useful
foxharp Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2020 Siddharth Dushantha
Copyright (c) 2025 Paul Fox

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

173 changes: 67 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,74 @@
<p align="center"><img src="extra/logo.png"><br><sub>✨ Very customizable and minimal font previewer written in bash ✨</sub></p>
<!-- doit: python3 -m markdown < README.md >README.html
-->

`fontpreview` is a commandline tool that lets you **quickly search** for fonts
that are installed on your machine and preview them. The **fuzzy search** feature
is provided by `fzf` and the preview is generated with `imagemagick` and then
displayed using `nsxiv`. This tool is **highly customizable**, almost all of the
variables in this tool can be changed using the commandline flags or you can
configure them using environment variables.
# fontpreview

![](extra/demo.gif)
This previewer started as a clone of
<https://github.com/sdushantha/fontpreview>,
written by github user sdushantha. They created a clever mechanism
for quickly getting a look at the contents of a font, in an easy to
navigate way. It's not clear that the original project is still being
maintained, so I've kind of had my way with the code, and it's diverged
quite a bit. The rest of the README describes my version, though from
a high level it's still pretty similar to sdushantha's.

__fontpreview__ lets you quickly search through installed fonts using
the __fzf__ "fuzzy matcher", and preview them. The previewer (any of
__sxiv__, __nsxiv__, or __feh__ will work) is normally reused for each
new font, but it's also possible to bring up a separate preview for
every selection.

![Animated screen showing fontpreview in use](extra/demo.gif)

## Dependencies

- `xdotool`
- `fzf`
- `imagemagick`
- `nsxiv`
Things you might need to fetch from your package manager:

- xdotool
- fzf
- imagemagick
- nsxiv, sxiv, or feh


## Usage Summary

usage:

fontpreview [options] <fontfile>
to preview a font from its file (.otf, .ttf)

fontpreview [options] <fontfile> <imagefile>
to create an image from the preview

fontpreview [options]
interactive use

Options:
-text text to be previewed
-font-size font size for the preview window
-no-preview-header don't include the font name in the preview
-multi-viewer spawn new viewer per font. (clean up manually.)
-bg-color <colorspec> background color for the preview window
-fg-color <colorspec> foreground color for the preview window
-size WxH width and height in pixels (overrides autosizing)
-position +X+Y/-X-Y position, as in X geometry (see "man X")

All options can be shortened to the first character of each word in
the option: e.g., '-fs' for '-font-size', or '-t' for '-text'.
(Or, reduced to the the shortest unique prefix.)
Either '-' or '--' can introduce any option.


## Installation
### Install using `make`
```bash
# Clone the repo
$ git clone https://github.com/sdushantha/fontpreview

# Change your current directory to fontpreview
$ cd fontpreview

# Install it
$ sudo make install
```

### Install it locally
```bash
# Download the fontpreview source code, save as fontpreview
# and make it executeable
$ curl -L https://git.io/raw_fontpreview > fontpreview && chmod +x fontpreview

# Then move fontpreview to somewhere in your $PATH
# Here is an example
$ mv fontpreview ~/scripts/
```

## Usage
```
$ fontpreview --help
usage: fontpreview [-h] [--size "px"] [--position "+x+y"] [--search-prompt SEARCH_PROMPT]
[--font-size "FONT_SIZE"] [--bg-color "BG_COLOR"] [--fg-color "FG_COLOR"]
[--preview-text "PREVIEW_TEXT"] [-i font.otf] [-o preview.png] [--version]

┌─┐┌─┐┌┐┌┌┬┐┌─┐┬─┐┌─┐┬ ┬┬┌─┐┬ ┬
├┤ │ ││││ │ ├─┘├┬┘├┤ └┐┌┘│├┤ │││
└ └─┘┘└┘ ┴ ┴ ┴└─└─┘ └┘ ┴└─┘└┴┘
Very customizable and minimal font previewer written in bash

optional arguments:
-h, --help show this help message and exit
-i, --input filename of the input font (.otf, .ttf, .woff are supported)
-o, --output filename of the output preview image (input.png if not set)
--size size of the font preview window
--position the position where the font preview window should be displayed
--search-prompt input prompt of fuzzy searcher
--font-size font size
--bg-color background color of the font preview window
--fg-color foreground color of the font preview window
--preview-text preview text that should be displayed in the font preview window
--version show the version of fontpreview you are using
```

If you want to generate a preview image for a **single** font file
(.otf, .ttf, and .woff are supported), use the `-i` and `-o` option
to indicate the filename of the input font and the output preview
image.

```
$ fontpreview -i font.otf -o preview.png
```

This can be used with [überzug](https://github.com/seebye/ueberzug)
to implement font preview within terminal file managers such as
[vifm](https://vifm.info/).

![](extra/vifm.png)

A detailed setup instructions can be found [here](https://krasjet.com/scribbles/font-preview.html)


## Configure
You can configure `fontpreview` through environment variables.

This can be in your `.bashrc`, `.zshrc`, etc

```bash
# Input prompt of fuzzy searcher
export FONTPREVIEW_SEARCH_PROMPT="❯ "

# Size of the font preview window
export FONTPREVIEW_SIZE=532x365

# The position where the font preview window should be displayed
export FONTPREVIEW_POSITION="+0+0"

# Font size
export FONTPREVIEW_FONT_SIZE=38

# Background color of the font preview window
export FONTPREVIEW_BG_COLOR="#ffffff"

# Foreground color of the font preview window
export FONTPREVIEW_FG_COLOR="#000000"

# Preview text that should be displayed in the font preview window
export FONTPREVIEW_PREVIEW_TEXT="ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n1234567890\n!@$\%(){}[]"
```
Simply download the script, make it executable, and put it in your
PATH somewhere. To download from github, click on the script "fontpreview",
then use the "hamburger" menu or ctrl-shift-s to download it. You'll need
to "```mv fontpreview.txt fontpreview```" after it's downloaded.

## Customization

Hey, it's a shell script -- customize all you want. ;-) If you
just want to change some of the predefined defaults for color, size,
etc, there's provision for putting those new definitions into
`$HOME/.fontpreview`. See the script for the names of the variables
that can be changed in that way.
Binary file modified extra/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading