tabularize auto-pager
[hband-tools.git] / xwin-tools / xscreenshot
blobe292fbd85eeb5b35a0c72d1f2662d66141ad4b4a
1 #!/bin/bash
3 coords=''
5 if [ ."$1" = .--region ]
6 then
7 shift
9 if [ ."$1" = .--repeat ]
10 then
11 shift
12 coords=`cat ~/.config/xscreenshot/last-selected-region`
15 if [ -z "$coords" ]
16 then
17 selection=$(xrectsel -p)
18 rc=$?
19 [ $rc = 0 ] || exit $rc
21 coords=$(echo "$selection" | sed -ne 1p)
23 if [ -n "$coords" ]
24 then
25 # select the whole window under the cursor if not a region was selected, just a point
26 if expr "$coords" : '^0x0[+-]' >/dev/null
27 then
28 coords=$(echo "$selection" | sed -ne 2p)
31 # save coordinates for later use
32 mkdir -p ~/.config/xscreenshot
33 echo "$coords" > ~/.config/xscreenshot/last-selected-region
38 filepath=~/tmp/screenshot_$(date +%F_%H%M%S).jpg
39 # may remove 'xwdtopnm' if your imagemagick version supports "X-Window screen dump" format
40 xwd -root | xwdtopnm | convert - ${coords:+-crop "$coords"} "$filepath"
41 exec mimeopen-gui "$filepath"