implement txt2printr.sh to send ascii art to a parallel port needle printer

writes raw bytes to /dev/lp0 (overridable via PRINTER_DEV): resets the
printer with ESC @, converts LF to CRLF to avoid staircasing on raw
device writes, then form-feeds to eject the page.
master
Amir Alexander Abdelbaki 2026-07-03 10:49:27 +02:00
parent 7030454075
commit 5b631adfe4
1 changed files with 25 additions and 0 deletions

View File

@ -1 +1,26 @@
#/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"