Butcher maim script

This commit is contained in:
Nox Sluijtman 2025-01-18 22:30:58 +01:00
parent c5f57dc4c5
commit 1ac63ac180
Signed by: Egg
SSH key fingerprint: SHA256:2sG9X3C7Xvq2svGumz1/k7cm8l4G9+qAtAeugqB4J9M

70
src/bin/butcher Executable file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env nu
# Copyright 2025 Marty Sluijtman <marty.wanderer@disroot.org>
# 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
}
}
}