summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2025-02-07 00:17:22 +0500
committerAnton Bobov <anton@bobov.name>2025-02-07 00:17:22 +0500
commit7e6f1da0c797b26d587071a07702c68873b6736d (patch)
tree3c1509d1da51bb0cebf20d3fcbe05e21040da6cb
parentda3c27abf212606850fb0c2f41cbdecfd99b1f01 (diff)
Cleaning ocr_screen script
-rwxr-xr-xocr_screen38
1 files changed, 24 insertions, 14 deletions
diff --git a/ocr_screen b/ocr_screen
index fc9cb76..5b72f5e 100755
--- a/ocr_screen
+++ b/ocr_screen
@@ -1,18 +1,28 @@
-#!/bin/sh
+#!/usr/bin/env bash
-if [ ! -x "$(command -v tesseract)" ] ; then
- echo "No tesseract executable"
- exit 1
-fi
-if [ ! -x "$(command -v scrot)" ] ; then
- echo "No scrot executable"
+set -euo pipefail
+
+check_command() {
+ if [ ! -x "$(command -v "$1")" ]; then
+ echo "No $1 executable"
exit 1
-fi
+ fi
+}
+
+main() {
+ check_command tesseract
+ check_command scrot
+ check_command mogrify
+ check_command xclip
+
+ TEMP_FILE=$(mktemp --suffix .png)
+ trap 'rm "$TEMP_FILE"' EXIT
+
+ ocr_language=${1:-eng}
-TEMP_FILE=$(mktemp --suffix .png)
-L=${1:-eng}
-trap "rm $TEMP_FILE" EXIT
+ scrot --select --quality 100 --overwrite "$TEMP_FILE" &&
+ mogrify -modulate 100,0 -resize 400% "$TEMP_FILE" &&
+ tesseract -l "$ocr_language" "$TEMP_FILE" - 2>/dev/null | xclip -sel clip
+}
-scrot --select --quality 100 --overwrite "$TEMP_FILE"
-mogrify -modulate 100,0 -resize 400% "$TEMP_FILE"
-tesseract -l $L "$TEMP_FILE" - 2>/dev/null | sed '/ /d' | xclip -sel clip
+main "$@"