Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
DEST ?= /usr/bin
PREFIX?= /usr
BINDIR= ${PREFIX}/bin

all:
@echo Run \'make install\' to install fontpreview on your device

install:
@cp fontpreview $(DEST)/fontpreview
@chmod 755 $(DEST)/fontpreview
@cp fontpreview $(DESTDIR)$(BINDIR)/fontpreview
@chmod 755 $(DESTDIR)$(BINDIR)/fontpreview
@echo fontpreview has been installed on your device

uninstall:
@rm -rf $(DEST)/fontpreview
@rm -rf $(DESTDIR)$(BINDIR)/fontpreview
@echo fontpreview has been removed from your device
35 changes: 19 additions & 16 deletions fontpreview
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#
# Dependencies: sxiv, imagemagick, xdotool, fzf

# Use mktemp to create temporary files that won't
# collide with any other application's tmp files.
FONTPREVIEW_DIR="$(mktemp -d --tmpdir fontpreview_dir_XXXXXXXX)"
PIDFILE="$(mktemp --tmpdir="$FONTPREVIEW_DIR" fontpreview_XXXXXXXX.pid)"
FONT_PREVIEW="$(mktemp --tmpdir="$FONTPREVIEW_DIR" fontpreview_XXXXXXXX.png)"
TERMWIN_IDFILE="$(mktemp --tmpdir="$FONTPREVIEW_DIR" fontpreview_XXXXXXXX.termpid)"
VERSION=1.0.4

# Default values
Expand Down Expand Up @@ -110,7 +104,7 @@ main(){

generate_preview "$font" "$FONT_PREVIEW"

if [ $FIRST_RUN == true ]; then
if [[ $FIRST_RUN == true ]]; then
FIRST_RUN=false

# Display the font preview using sxiv
Expand All @@ -126,19 +120,18 @@ main(){
# sxiv when the user exits the script
echo $! >"$PIDFILE"

# Check for crashes of sxiv
elif [ -f $PIDFILE ] ; then
PID=$(cat $PIDFILE)
if [ ! -e /proc/$PID ] ; then
# Check for crashes of sxiv
elif [[ -f $PIDFILE ]] ; then
if ! pgrep -F "$PIDFILE" >/dev/null 2>&1; then
echo "Restart sxiv - You maybe using a obsolete version. " >&2
# Display the font preview using sxiv
sxiv -g "$SIZE$POSITION" "$FONT_PREVIEW" -N "fontpreview" -b &
sxiv -g "$SIZE$POSITION" -N "fontpreview" -b "$FONT_PREVIEW" &

# Change focus from sxiv, back to the terminal window
# so that user can continue to search for fonts without
# having to manually change focus back to the terminal window
xdotool windowfocus "$(cat "$TERMWIN_IDFILE")"

# Save the process ID so that we can kill
# sxiv when the user exits the script
echo $! >"$PIDFILE"
Expand All @@ -155,18 +148,28 @@ trap "" SIGTSTP

trap pre_exit EXIT

# Use mktemp to create a temporary directory that won't
# collide with temporary files of other application.
FONTPREVIEW_DIR="$(mktemp -d "${TMPDIR:-/tmp}/fontpreview_dir.XXXXXXXX")" || exit
PIDFILE="$FONTPREVIEW_DIR/fontpreview.pid"
touch "$PIDFILE" || exit
FONT_PREVIEW="$FONTPREVIEW_DIR/fontpreview.png"
touch "$FONT_PREVIEW" || exit
TERMWIN_IDFILE="$FONTPREVIEW_DIR/fontpreview.termpid"
touch "$TERMWIN_IDFILE" || exit
Comment thread
sdushantha marked this conversation as resolved.

# Parse the arguments
options=$(getopt -o hi:o: --long position:,size:,version,search-prompt:,font-size:,bg-color:,fg-color:,preview-text:,input:,output:,help -- "$@")
eval set -- "$options"

while true; do
case "$1" in
--size)
shift;
shift
FONTPREVIEW_SIZE=$2
;;
--position)
shift;
shift
FONTPREVIEW_POSITION=$2
;;
-h|--help)
Expand Down