package ocr script with dependencies

This commit is contained in:
Noah Masur 2022-10-25 20:22:17 -04:00
parent be581dba1f
commit 3dcafb8c25
3 changed files with 26 additions and 10 deletions

View File

@ -1,4 +1,19 @@
{ config, pkgs, lib, ... }: {
{ config, pkgs, lib, ... }:
let
# Quickly package shell scripts with their dependencies
# From https://discourse.nixos.org/t/how-to-create-a-script-with-dependencies/7970/6
mkScript = { name, file, env ? [ ] }:
pkgs.writeScriptBin name ''
for i in ${lib.concatStringsSep " " env}; do
export PATH="$i/bin:$PATH"
done
exec ${pkgs.bash}/bin/bash ${file} $@
'';
in {
home-manager.users.${config.user} = {
@ -17,9 +32,11 @@
consul
noti # Create notifications programmatically
ipcalc # Make IP network calculations
whois # Lookup IPs
(pkgs.writeScriptBin "ocr"
(builtins.readFile ../shell/bash/scripts/ocr.sh))
(mkScript {
name = "ocr";
file = ../shell/bash/scripts/ocr.sh;
env = [ tesseract ];
})
];
programs.fish.shellAbbrs = {

View File

@ -1,5 +1,4 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p tesseract
#!/usr/bin/env bash
# Yoinked from https://github.com/JJGO/dotfiles
# Adapted from https://github.com/sdushantha/bin
@ -9,13 +8,13 @@ TEXT_FILE="/tmp/ocr.txt"
IMAGE_FILE="/tmp/ocr.png"
function notify-send() {
osascript -e "display notification \"$2\" with title \"OCR\""
/usr/bin/osascript -e "display notification \"$2\" with title \"OCR\""
}
PATH="/usr/local/bin/:$PATH"
# Take screenshot by selecting the area
screencapture -i "$IMAGE_FILE"
/usr/sbin/screencapture -i "$IMAGE_FILE"
# Get the exit code of the previous command.
# So in this case, it is the screenshot command. If it did not exit with an
@ -44,7 +43,7 @@ fi
# Copy text to clipboard
# xclip -selection clip < "$TEXT_FILE"
pbcopy <"$TEXT_FILE"
/usr/bin/pbcopy <"$TEXT_FILE"
# Send a notification with the text that was grabbed using OCR
notify-send "ocr" "$(cat $TEXT_FILE)"

View File

@ -31,7 +31,7 @@ in {
vimv-rs # Batch rename files
dig # DNS lookup
lf # File viewer
whois # Lookup IPs
# whois # Lookup IPs
age # Encryption
];