rework shot() to be easier to use, and save local copies of pasted shots

This commit is contained in:
David Thurstenson 2017-06-02 16:00:52 -05:00
parent a030520c1f
commit 3bc4f991cf
1 changed files with 49 additions and 15 deletions

64
.bashrc
View File

@ -132,38 +132,72 @@ countdown() {
shot() { shot() {
# Usage: shot XY # Usage: shot XY
local destdir="$HOME/Pictures/screenshots" local destdir="$HOME/Pictures/screenshots"
local fname="screenshot-$(date +%F-%T).png" local fname="shot-$(date +%F-%T).png"
local fpath="${destdir}/${fname}"
local pb="fb" local pb="fb"
local pipe local paste msgt msgd opts
local -a 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 # X: What to capture
case ${1:0:1} in case ${1:0:1} in
# Active window # Active window
w) w) printf "Focus target window now...\n"
countdown 5 opts="-i $(xdotool getactivewindow)"
opts[0]="-i$(xdotool getactivewindow)" msgt="active window"
;; ;;
# All # All
a) opts[0]="";; a) msgt="all displays"
;;
# Mouse selection # Mouse selection
s) opts[0]="-s --noopengl";; s) opts="-s --noopengl"
msgt="mouse selection"
;;
*) printf "Unknown target: %s\n" "${1:0:1}"
return
;;
esac esac
#Y: Where to put the result #Y: Where to put the result
case ${1:1:1} in case ${1:1:1} in
# Save to file # Save to file
f) [ ! -d "$destdir" ] && mkdir -p "$destdir" f) msgd="file: $destdir/$fname"
opts[1]="$fpath"
printf "Writing to %s\n" "$fpath"
;; ;;
# Post to a pastebin # Post to a pastebin
p) opts[1]="/tmp/$fname" p) destdir=$destdir/pasted
pipe="$pb ${opts[1]}";; msgd="pastebin"
paste=1;;
*) printf "Unknown destination: %s\n" "${1:1:1}"
return
;;
esac 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() { fontfind() {