diff --git a/bin/glurp b/bin/glurp index f387df9..4cc648f 100755 --- a/bin/glurp +++ b/bin/glurp @@ -1,61 +1,52 @@ -#!/bin/bash +#!/bin/sh -# Functions -# Error -function error { - >&2 echo -e "\033[1;31mERROR:\033[0m $1"; shift - exit "${1:-1}" +error_usage() { + >&2 cat << EOF +Usage : + glurp full|area clip|file +EOF + exit 1 } -# Throw a value -function throw-value { - error "Value \"${1}\" invalid for ${2}." 1 +screenshot_path() { + printf %s "/tmp/screenshot-${USER}-$(date +%N).png" } -function screenshot-path { - printf '%s%s-screenshot-%s.png' "${screenshot_d}/" "${LOGNAME}" "$(date +'%Y_%m_%d_%s')" -} - -# Variables -declare -a prepend _command append -screenshot_d=/tmp +grim=grim +wl_copy_args="-t image/png" # Arguments -selection_mode="$1"; shift -saving_mode="$1" ; shift - -# Command building -_command+=(grim) -case "$selection_mode" in +case "$1" in full) - : ;; area) - _command+=(-g -) - prepend+=(slurp) + slurp=slurp + pipe1='|' + grim_args="-g -" ;; *) - throw-value "$selection_mode" 'selection mode' + error_usage ;; esac -case "$saving_mode" in +shift + +case "$1" in clip) - _command+=(-) - append+=(wl-copy -t image/png) + pipe2='|' + wl_copy=wl-copy ;; file) - _command+=("$(screenshot-path)") + grim_args="${grim_args} $(screenshot_path)" ;; *) - throw-value "$saving_mode" 'saving mode' + error_usage ;; esac +shift -# Debug -#echo "${prepend[@]} | ${_command[@]} | ${append[@]}" -#exit 0 +[ -n "$wl_copy" ] && wl_copy="${wl_copy} ${wl_copy_args}" # Execution set -xe -"${prepend[@]}" | "${_command[@]}" | "${append[@]}" +"$slurp" "$pipe1" "$grim" "$grim_args" "$pipe2" "$wl_copy"