From 3dcafb8c25373edc78406e98b7737ca22ac6ffb9 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:22:17 -0400 Subject: [PATCH] package ocr script with dependencies --- modules/darwin/utilities.nix | 25 +++++++++++++++++++++---- modules/shell/bash/scripts/ocr.sh | 9 ++++----- modules/shell/utilities.nix | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/darwin/utilities.nix b/modules/darwin/utilities.nix index d73a6c3..30b509b 100644 --- a/modules/darwin/utilities.nix +++ b/modules/darwin/utilities.nix @@ -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 = { diff --git a/modules/shell/bash/scripts/ocr.sh b/modules/shell/bash/scripts/ocr.sh index 1a6b0c7..313a069 100755 --- a/modules/shell/bash/scripts/ocr.sh +++ b/modules/shell/bash/scripts/ocr.sh @@ -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)" diff --git a/modules/shell/utilities.nix b/modules/shell/utilities.nix index d5d09e2..33d9c49 100644 --- a/modules/shell/utilities.nix +++ b/modules/shell/utilities.nix @@ -31,7 +31,7 @@ in { vimv-rs # Batch rename files dig # DNS lookup lf # File viewer - whois # Lookup IPs + # whois # Lookup IPs age # Encryption ];