From 3bc4f991cf9395a63fa8e090e07dc53f1be5b300 Mon Sep 17 00:00:00 2001 From: David Thurstenson Date: Fri, 2 Jun 2017 16:00:52 -0500 Subject: [PATCH] rework shot() to be easier to use, and save local copies of pasted shots --- .bashrc | 64 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/.bashrc b/.bashrc index 6de055f..448b644 100644 --- a/.bashrc +++ b/.bashrc @@ -132,38 +132,72 @@ countdown() { shot() { # Usage: shot XY local destdir="$HOME/Pictures/screenshots" - local fname="screenshot-$(date +%F-%T).png" - local fpath="${destdir}/${fname}" + local fname="shot-$(date +%F-%T).png" local pb="fb" - local pipe - local -a opts + local paste msgt msgd opts + + if [ -z "$1" ]; then + printf "Usage: shot XY +X: Target +Y: Destination + +Valid Targets: +w Active Window +a All displays +s Mouse Selection + +Valid Destinations: +f Save to file (defined in function) +p Upload to a pastebin (defined in function) +" + return + fi # X: What to capture case ${1:0:1} in # Active window - w) - countdown 5 - opts[0]="-i$(xdotool getactivewindow)" + w) printf "Focus target window now...\n" + opts="-i $(xdotool getactivewindow)" + msgt="active window" ;; # All - a) opts[0]="";; + a) msgt="all displays" + ;; # Mouse selection - s) opts[0]="-s --noopengl";; + s) opts="-s --noopengl" + msgt="mouse selection" + ;; + + *) printf "Unknown target: %s\n" "${1:0:1}" + return + ;; esac #Y: Where to put the result case ${1:1:1} in # Save to file - f) [ ! -d "$destdir" ] && mkdir -p "$destdir" - opts[1]="$fpath" - printf "Writing to %s\n" "$fpath" + f) msgd="file: $destdir/$fname" ;; # Post to a pastebin - p) opts[1]="/tmp/$fname" - pipe="$pb ${opts[1]}";; + p) destdir=$destdir/pasted + msgd="pastebin" + paste=1;; + + *) printf "Unknown destination: %s\n" "${1:1:1}" + return + ;; esac - maim ${opts[@]}; $pipe + # Make sure destination directory will exist + [[ ! -d "$destdir" ]] && mkdir -p "$destdir" + local fpath="${destdir}/${fname}" + # If target is active window, give a 5 second countdown before running maim + [[ "$msgt" = "active window" ]] && countdown 5 + + maim $opts "$fpath" + printf "Captured %s -> %s\n" "$msgt" "$msgd" + # If destination is a pastebin, do the needful + [[ "$paste" ]] && $pb "$fpath" } fontfind() {