27 lines
803 B
Bash
Executable File
27 lines
803 B
Bash
Executable File
#/bin/bash
|
|
#
|
|
# Sends an ascii-art text file to a parallel port needle/dot-matrix printer.
|
|
#
|
|
# Usage: ./txt2printr.sh [ascii-art.txt]
|
|
# Env: PRINTER_DEV - printer device node (default: /dev/lp0)
|
|
|
|
infile="${1:-ascii-img.txt}"
|
|
dev="${PRINTER_DEV:-/dev/lp0}"
|
|
|
|
if [ ! -f "$infile" ]; then
|
|
echo "txt2printr: file not found: $infile" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -w "$dev" ]; then
|
|
echo "txt2printr: cannot write to printer device: $dev" >&2
|
|
echo "txt2printr: set PRINTER_DEV to override, or check permissions/parport module" >&2
|
|
exit 1
|
|
fi
|
|
|
|
{
|
|
printf '\x1b\x40' # ESC @ - reset printer (ESC/P and IBM Proprinter compatible)
|
|
sed 's/$/\r/' "$infile" # CRLF line endings, needed for raw writes to avoid staircasing
|
|
printf '\x0c' # form feed - eject the page
|
|
} > "$dev"
|