From 725c400e223e8c07f290f77ef40bcc03774b5a91 Mon Sep 17 00:00:00 2001 From: Suleyman Farajli Date: Sat, 27 Jul 2024 16:14:37 +0400 Subject: shot: screenshot wrapper added --- scripts/shot | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/shot b/scripts/shot index 4bebce2..fd56dd8 100755 --- a/scripts/shot +++ b/scripts/shot @@ -31,6 +31,7 @@ run() { } default_dir="${HOME}"/pics/screenshots + s_flg="" while getopts "d:sh" option; do case "${option}" in @@ -46,30 +47,24 @@ done shift $((OPTIND - 1)) -if [ $# != 0 ];then - err "${0}: Invalid usage" \ - "Try '${0} -h' for help." -fi - -if [ -n "${input}" ]; then - case $(file -b --mime-type "${input}") in - image/*) outfile="${input}" ;; - - inode/directory) outdir="${input}" ;; - - *) err "Couldn't read given file" ;; - esac -fi +[ ${#} != 0 ] && err "${0}: Invalid usage" "Try '${0} -h' for help." -if [ -z "${outfile}" ]; then - if [ -z "${outdir}" ]; then - [ ! -d "${default_dir}" ] && mkdir -pv "${default_dir}" - outdir="${default_dir}" +if [ -z "${input}" ]; then + outfile="${default_dir}"/%b%d::%H%M%S.png +else + if [ -d "${input}" ]; then + outfile="${input}"/%b%d::%H%M%S.png + else + outfile="${input}" fi - outfile="${outdir}"/%b%d::%H%M%S.png fi +if [ ! -e "$(dirname "${outfile}")" ]; then + mkdir -pv "$(dirname "${outfile}")" > /dev/null 2>&1 \ + || err "${0}: Failed to create directory" +fi + if [ "${s_flg}" = "1" ]; then run "scrot -zs ${outfile}" "Failed to screenshot" else -- cgit v1.2.3