From 1ac63ac1809729ce28f3cc5d729d3815f4def3d3 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sat, 18 Jan 2025 22:30:58 +0100 Subject: [PATCH] Butcher maim script --- src/bin/butcher | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 src/bin/butcher diff --git a/src/bin/butcher b/src/bin/butcher new file mode 100755 index 0000000..10b47c2 --- /dev/null +++ b/src/bin/butcher @@ -0,0 +1,70 @@ +#!/usr/bin/env nu +# Copyright 2025 Marty Sluijtman +# Distributed under the terms of the GPLv3 license + +let savedir = match ($env.SCROTDIR | is-empty) { + true => $"($env.HOME)/Pictures/Screenshots" + false => $env.SCROTDIR +} + +let date = ^date -Iseconds +let filename = $"($savedir)/($date)_screenshot.png" + +def notify [message: string] { + ^notify-send "Butcher" $message +} + +def clipboard [] { + $in | ^pngquant - | ^xclip -sel clip -t image/png +} + +def main [--clipboard (-c)] { + let scrot = ^maim -ui root | complete + match $clipboard { + true => { + $scrot.stdout | clipboard + notify "Shot entire screen and tossed the output to the clipboard" + } + false => { + $scrot.stdout | save $filename + notify $"Shot entire screen and saved the result to:\n($filename)" + } + } +} + +def "main window" [--clipboard (-c)] { + let window = ^xdotool getactivewindow + let scrot = ^maim -ui $window | complet + match $clipboard { + true => { + $scrot.stdout | clipboad + notify $"Took screenshot of focussed window and tossed it to clipboard" + } + false => { + $scrot.stdout | save $filename + notify $"Saved screenshot of focussed window and save it to:\n($filename)" + } + } +} + +def "main selection" [--clipboard(-c)] { + let scrot = ^maim -su | complete + match $scrot.exit_code { + 0 => { + match $clipboard { + true => { + $scrot.stdout | clipboard + notify "Took screenshot and tossed it to clipboard" + } + false => { + $scrot.stdout | save $filename + notify $"Shot selection and saved it to:\n($filename)" + } + } + } + _ => { + notify "Screenshot selection cancelled" + exit 0 + } + } +}