1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

refactor(screenshots): use separate scripts package

This commit is contained in:
oddlama 2023-10-16 00:46:30 +02:00
parent 3e0e03fc31
commit 6e8aae7d8d
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
15 changed files with 216 additions and 109 deletions

View file

@ -1,6 +1,6 @@
self: super: let
_final: prev: let
inherit
(self.lib)
(prev.lib)
escapeShellArg
concatMapStrings
flip
@ -20,9 +20,9 @@ self: super: let
version,
}: "go get ${escapeShellArg name}@${escapeShellArg version}\n");
in
super.caddy.override {
prev.caddy.override {
buildGoModule = args:
super.buildGoModule (args
prev.buildGoModule (args
// {
inherit vendorHash;
passthru.plugins = plugins;
@ -44,5 +44,5 @@ in {
# ];
# vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
# }
caddy = super.caddy.overrideAttrs (_: {passthru.withPackages = make-custom-caddy;});
caddy = prev.caddy.overrideAttrs (_: {passthru.withPackages = make-custom-caddy;});
}

View file

@ -1,21 +1,22 @@
[
(import ./caddy.nix)
(import ./oauth2-proxy)
(_self: super: {
deploy = super.callPackage ./deploy.nix {};
git-fuzzy = super.callPackage ./git-fuzzy {};
kanidm-secret-manipulator = super.callPackage ./kanidm-secret-manipulator.nix {};
segoe-ui-ttf = super.callPackage ./segoe-ui-ttf.nix {};
zsh-histdb-skim = super.callPackage ./zsh-skim-histdb.nix {};
(import ./scripts)
(_final: prev: {
deploy = prev.callPackage ./deploy.nix {};
git-fuzzy = prev.callPackage ./git-fuzzy {};
kanidm-secret-manipulator = prev.callPackage ./kanidm-secret-manipulator.nix {};
segoe-ui-ttf = prev.callPackage ./segoe-ui-ttf.nix {};
zsh-histdb-skim = prev.callPackage ./zsh-skim-histdb.nix {};
kanidm = super.kanidm.overrideAttrs (_finalAttrs: _previousAttrs: {
kanidm = prev.kanidm.overrideAttrs (_finalAttrs: _previousAttrs: {
patches = [
(super.fetchpatch {
(prev.fetchpatch {
name = "group-list-json-output.patch";
url = "https://patch-diff.githubusercontent.com/raw/kanidm/kanidm/pull/2016.patch";
hash = "sha256-gc75KBzhth4fZvuvRa3Rjg1J7DIGy25mzUPCf2aha80=";
})
(super.fetchpatch {
(prev.fetchpatch {
name = "person-and-oauth-json-output.patch";
url = "https://patch-diff.githubusercontent.com/raw/kanidm/kanidm/pull/2017.patch";
hash = "sha256-fZgJ7dY2LHvBi64A/6o7kfArUAsLqjWRRpH2q1GL5ic=";
@ -26,9 +27,9 @@
});
formats =
super.formats
prev.formats
// {
ron = import ./ron.nix {inherit (super) lib pkgs;};
ron = import ./ron.nix {inherit (prev) lib pkgs;};
};
})
]

7
pkgs/scripts/default.nix Normal file
View file

@ -0,0 +1,7 @@
_final: prev: {
scripts = {
screenshot-area = prev.callPackage ./screenshot-area.nix {};
screenshot-area-scan-qr = prev.callPackage ./screenshot-area-scan-qr.nix {};
screenshot-screen = prev.callPackage ./screenshot-screen.nix {};
};
}

View file

@ -0,0 +1,58 @@
{
writeShellApplication,
libnotify,
xclip,
maim,
zbar,
yq,
}:
writeShellApplication {
name = "screenshot-area-scan-qr";
text = ''
set -euo pipefail
umask 077
# Create in-memory tmpfile
TMPFILE=$(mktemp)
exec 3<>"$TMPFILE"
rm "$TMPFILE" # still open in-memory as /dev/fd/3
TMPFILE=/dev/fd/3
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png"
mkdir -p "$(dirname "$out")"
if ${maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select \
| ${zbar}/bin/zbarimg --xml - > "$TMPFILE"; then
N=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE")
# Append codes Copy data separated by ---
DATA=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE")
for ((i=1;i<N;++i)); do
DATA="$DATA"$'\n'"---"$'\n'"$(${yq}/bin/xq -r ".barcodes.source.index.symbol[$i].data" < "$TMPFILE")"
done
${xclip}/bin/xclip -selection clipboard <<< "$DATA"
${libnotify}/bin/notify-send \
"🔍 QR Code scan" " $N codes detected\n📋 copied ''${#DATA} bytes" \
--hint="string:image-path:$out" \
--hint="string:wired-tag:screenshot-$date" \
|| true
else
case "$?" in
"4")
${libnotify}/bin/notify-send \
"🔍 QR Code scan" " 0 codes detected" \
--hint="string:image-path:$out" \
--hint="string:wired-tag:screenshot-$date" \
|| true
;;
*)
${libnotify}/bin/notify-send \
"🔍 QR Code scan" " Error while processing image: zbarimg exited with code $?" \
--hint="string:image-path:$out" \
--hint="string:wired-tag:screenshot-$date" \
|| true
;;
esac
fi
'';
}

View file

@ -0,0 +1,46 @@
{
writeShellApplication,
libnotify,
xclip,
tesseract,
maim,
}:
writeShellApplication {
name = "screenshot-area";
text = ''
set -euo pipefail
umask 077
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png"
mkdir -p "$(dirname "$out")"
${maim}/bin/maim --color=.4,.7,1,0.2 --bordersize=1.0 --nodecorations=1 \
--hidecursor --format=png --quality=10 --noopengl --select "$out"
${xclip}/bin/xclip -selection clipboard -t image/png < "$out"
action=$(${libnotify}/bin/notify-send \
"📷 Screenshot captured" "📋 copied to clipboard" \
--hint="string:wired-tag:screenshot-$date" \
--action=ocr=OCR) \
|| true
if [[ "$action" == "ocr" ]]; then
${libnotify}/bin/notify-send \
"📷 Screenshot captured" " Running OCR ..." \
--hint="string:wired-tag:screenshot-$date" \
|| true
if ${tesseract}/bin/tesseract "$out" - -l eng+deu | ${xclip}/bin/xclip -selection clipboard; then
${libnotify}/bin/notify-send \
"📷 Screenshot captured" "🔠 OCR copied to clipboard" \
--hint="string:wired-tag:screenshot-$date" \
|| true
else
${libnotify}/bin/notify-send \
"📷 Screenshot captured" " Error while running OCR" \
--hint="string:wired-tag:screenshot-$date" \
|| true
fi
fi
'';
}

View file

@ -0,0 +1,20 @@
{
writeShellApplication,
libnotify,
maim,
}:
writeShellApplication {
name = "screenshot-screen";
text = ''
set -euo pipefail
umask 077
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$(date +"%Y-%m-%dT%H:%M:%S%:z")-fullscreen.png"
mkdir -p "$(dirname "$out")"
${maim}/bin/maim --hidecursor --format=png --quality=10 --noopengl "$out"
${libnotify}/bin/notify-send \
"📷 Screenshot captured" "💾 Saved to $out" \
|| true
'';
}