Git Product home page Git Product logo

fontpreview's Introduction


✨ Very customizable and minimal font previewer written in bash ✨

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.

Dependencies

  • xdotool
  • fzf
  • imagemagick
  • nsxiv

Installation

Install using make

# 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

# 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 to implement font preview within terminal file managers such as vifm.

A detailed setup instructions can be found here

Configure

You can configure fontpreview through environment variables.

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

# 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!@$\%(){}[]"

fontpreview's People

Contributors

0mp avatar birma avatar elsorino avatar erenhatirnaz avatar imgbotapp avatar krasjet avatar maxdevjs avatar misterhackerman avatar sdushantha avatar sebastianmeisel avatar tastytea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fontpreview's Issues

[Feature Request] Add MacOS support

So far I have tried 3 image viewers:

  • macfeh - Does not reload the image when the image gets altered. The normal feh has an --auto-reload option, but macfeh doesnt, and it does not look it will be added if we ask for it because the developer has not been active for a really long time.

  • qlmanage (Quick Look) - Does not reload the image when the image gets altered

  • Preview.app - Is able to reload the image using a small hack. But the down side of using preview is that it does not look minimal. It is possible to hide the tool bar and some of the junk, but I am not sure if it is possible to do so from the command line.

To change the focus from the image viewer back to the terminal, we can of course use Apple Script.

Include font name in the preview window.

When opening a font with fontpreview the window only has "sxiv" as the title. If multiple fonts are opened it becomes hard to keep track which fontpreview window shows which font.

So including the proper name of the font in the preview window might better user experience.

Only works with one font at a time

For me the font preview works only for one font. When I want to preview a second font I have to quit and restart the script.

Ubuntu 18.04
bash 4.4.20

Arabic Font's

Very cool code, thank you for your effort, but there is a minor problem, which is that the code does not support the Arabic language for fonts. Please solve this problem
Screenshot from 2023-08-21 15-44-20

Fontpreview doesn't find any fonts in the system

Hey,

I came to try the tool from Reddit (looked really nice and handy). Actually, the issue is that it can't find any fonts in my distribution (i.e. Pop! OS 18.04 LTS (uses Ubuntu as its base)).

Going through the code on line 105.

image

^^ I found out the command which finds the fonts and runs awk on the output. The issue lies in awk not being able to parse the output correctly.

Fonts Output:
image

After getting the fonts and running awk on it:
image

The actual script (fontpreview)'s output:
image

Appreciate you looking into it. Let me know if further details are required to resolve the issue.

Show font path

I sometimes make projects that need fonts bundled. This requires me to find out where I installed my fonts to. The system font viewer isn't really helpful at this. So, I would really appreciate if the path of fonts was displayed after the fontnames given a flag such as --show-path.

Tagging releases

Hi!

I would be super nice if you could tag releases with git tag. It makes it much easier to track development and package this nice tool for various package managers.

Thanks!

Info: Reimplementation in Emacs Lisp

Hello,

I just want to inform you, that I started a reimplementation of fontpreview in Emacs Lisp,
because I often need fontnames for projects within Emacs. It's still in an early stage. Just
thought, you might want to know.
I gave you credits of course.

Sebastian Meisel

Have to click back to the terminal every time I load a font

Every time I load a font, the window focus goes to the preview window and I have to click on the terminal to set focus back to the font selection.
Is it possible to make it retain focus on the font selection window (terminal)?

I'm sure not everything here is needed to reproduce but here is my current setup:

OS: Debian GNU/Linux 10 (buster) x86_64
Kernel: 4.19.0-6-amd64
DE: KDE
WM: KWin
WM Theme: Materia-Manjaro-Dark-Gradient
Theme: Breeze Dark [KDE], Breeze [GTK2/3]
Icons: Materia-Manjaro-Dark-2 [KDE], breeze [GTK2/3]
Terminal: konsole

Preview all fonts

Feature idea

Preview all font at once (with a custom text eg. using --preview-text ) in a list (one font per line).

Would make it easy to compare lot of fonts at once.

Fix RTL text

Currently, if a RTL language is passed to fontpreview via --preview-text, it appears backwards. Can be seen with the following text:

קצת טקסט בעברית
which gives the following output:
wrong-direction

[Strategy] solved focus issue

Two points:

  • does not switch the focus back to the terminal
  • quitting sxiv, then fzf gets confused

I got the first working in terminal, but not yet in fontpreview.
The second will probalby need a review of opening/closing strategy.

Let me know :)

[Feature Request] Implement title with font name and style elements (or Postscript name)

Please implement a title in the font preview window, which should show the font name and style or the postscript name.

Use case

Fonts have often misleading names, sometimes still in the DOS 8.3 naming convention. For similar-looking fonts, it's not easy to see which font it really is if you don't see the real font name embedded in the font. Font names like bookosb.ttf and bookosbi.ttf don't tell much if you need a certain font, for example in LibreOffice which shows the real font names and not the file names.

Example code

fc-scan --format "%{fullname[$(( $(sed -E 's/^(.*)en.*/\1/;s/[^,]//g' <<<"$(fc-scan --format "%{fullnamelang}\n" /mnt/Fonts/bookosb.ttf)" | wc -c) -1 ))]}\n" /mnt/Fonts/bookosb.ttf

is a way to retrieve the font name wherever fontconfig is installed, so practically everywhere on Linux. The complex line is necessary because a simple fc-scan --format "%{fullname}\n" would return something like

Bookman Old Style Negreta,Bookman Old Style tučné,Bookman Old Style fed,Bookman Old Style Fett,Bookman Old Style Έντονα,Bookman Old Style Bold,Bookman Old Style Negrita,Bookman Old Style Lihavoitu,Bookman Old Style Gras,Bookman Old Style Félkövér,Bookman Old Style Grassetto,Bookman Old Style Vet,Bookman Old Style Halvfet,Bookman Old Style Pogrubiony,Bookman Old Style Negrito,Bookman Old Style Полужирный,Bookman Old Style Fet,Bookman Old Style Kalın,Bookman Old Style Krepko,Bookman Old Style Lodia

instead of just

Bookman Old Style Bold

Alternatively, fc-scan --format "%{postscriptname}\n" is simpler, but returns

  • BookmanOldStyle-Bold*

which needs to be parsed by the user to get the proper name for linux use.

[Feature Request] Replace sxiv with überzug?

I just learned from @Krasjet that you can use überzug to display the font preview right on the terminal! Which is AWESOME!

I was thinking that we could use fzf's preview window to display the font preview image. This means users wont have to press [ENTER], to view the font preview because fzf automatically displays the content in the preview window just by highlighting it.

This would also fix the issues (#12) many users we having with xdotool not working properly.

Also, using überzug would mean that everything would be in one window instead of having a separate window for the font preview.

@aeghn has made a PR(#13) to add keybindings to do certain action in fzf. So if we do add the überzug image preview, we can then quickly remove the image to display the help menu in fzf's preview window.

Let me know what you guys think!


PS. I cant work a lot on project for the next 2 weeks because I will be very busy, so if someone wants push access please do contact me :)

New maintainers wanted

Hello :)

I am very busy at the moment with school related things and would like to focus more on that for some time. So, I was wondering if any of you, with some good knowledge with bash, would like to get push access to this repo so that you can merge PRs, and push edits to the repo and keep this project alive?

If you are interested, please do contact me by email (check my profile).

Put demo.gif somewhere else

I have really slow connection to github. As a result, I can only clone the repo at ~15KiBps. A single demo.gif takes up 5.93MB, which is larger than all other files combined (the repo weighs only 21KB after the removal).

Solution: use an image hosting service and embed the image in README.

Probably not intended install location for AUR package

In the PKGBUILD file on AUR

package() {
  cd "$pkgname/"
  make DEST="$pkgdir/" install
  install -D -m644 LICENSE "$pkgdir/usr/share/licenses/fontpreview/LICENSE.md"
}

The executable will be located at root / by default which is probably not intended.

--preview-text has no effect for preview generation

Hello
this will not work for now:
./fontpreview -i /home/jd/Productions/B/BLionTaleFont/BLionTale-Regular.otf --preview-text "BONSOIR" -o a.png
expected: a.png shows a BONSOIR word
encountered: a.png contains the whole default alphabet

:)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.