File: pdf_viewer.sh

package info (click to toggle)
clifm 1.26.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,816 kB
  • sloc: ansic: 64,595; sh: 3,133; python: 1,851; makefile: 567
file content (30 lines) | stat: -rwxr-xr-x 645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

# A PDF text viewer plugin for Clifm
# Dependencies: pdftotext

# Written by L. Abramovich
# License: GPL2+

if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
	name="${CLIFM_PLUGIN_NAME:-$(basename "$0")}"
	printf "Visualize PDF files in the terminal\n"
	printf "\n\x1b[1mUSAGE\x1b[0m\n  %s FILE\n" "$name"
	exit 0
fi

if ! type pdftotext >/dev/null 2>&1; then
	printf "clifm: pdftotext: Command not found\n" >&2
	exit 127
fi

file="$(echo "$1" | sed 's/\\//g')"

if [ "$(head -c4 "$file")" != "%PDF" ]; then
	printf "clifm: Not a PDF file\n" >&2
	exit 1
fi

pdftotext -nopgbrk -layout "$file" - | ${PAGER:=less}

exit 0