diff options
author | sinanmohd <sinan@firemail.cc> | 2023-08-23 18:43:30 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-08-23 18:43:30 +0530 |
commit | 200c42685401a7155ee436c8026881fcada9486c (patch) | |
tree | 01277d242cd5689624c64728a3b1cee5750818dd /.local | |
parent | d5d7399ba108f5d8a082c1a8ff082bf7d7e6b9de (diff) |
freezshot: initial commit
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/freezshot | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/.local/bin/freezshot b/.local/bin/freezshot new file mode 100755 index 0000000..81b5bd2 --- /dev/null +++ b/.local/bin/freezshot @@ -0,0 +1,62 @@ +#!/bin/sh + +tmp="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}" +tmp="$(mktemp -d "${tmp}/freezhot.XXXX")" +out="${GRIM_DEFAULT_DIR:-${XDG_PICTURES_DIR:-.}}" + +note() +{ + : "${1:?}" + + command -v notify-send > /dev/null && + notify-send " freezshot" "$1" +} + +die() +{ + printf "\033[31;1merr: %b\033[0m\n" "$1" 1>&2 + exit "${2:-1}" +} + +dep_check() +{ + for dep; do + command -v "$dep" > /dev/null || + die "$dep is not installed" 127 + done + + unset dep +} + +wl_res() +{ + wlr-randr | while read -r line; do + case "$line" in + *"current)") + echo "${line% px*}" + return + esac + done +} + +######## +# MAIN # +######## + +dep_check grim slurp imv wlr-randr +[ -d "$out" ] || mkdir -p "$out" + +GRIM_DEFAULT_DIR="$tmp" grim +imv -f "$tmp"/* & +view_pid=$! + +if region=$(slurp) > /dev/null 2>&1; then + if [ "${region#* }" = "$(wl_res)" ]; then + cp "$tmp"/* "$out" + else + grim -g "$region" + fi +fi + +kill $view_pid +rmdir "$tmp" |