diff options
author | Peter Palfrader <peter@palfrader.org> | 2012-03-30 13:32:28 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2012-03-30 13:32:28 +0000 |
commit | 22aaa1f635663753b11ed78b78d3a2230f1764fa (patch) | |
tree | 654b45bb938cf29a6f19999cbb98668cc29fdf0d /publish | |
parent | c74801223e17e5d5c114d127c6ba85504c474ce2 (diff) |
Update tempfile handling; support QR code generation
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@513 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'publish')
-rwxr-xr-x | publish | 89 |
1 files changed, 55 insertions, 34 deletions
@@ -72,6 +72,7 @@ OPTIONS: -S Make a screenshot of one window and publish. -x Publish the contents of the xclipboard -h Show this message + -q Produce a QR code EOF } @@ -96,17 +97,29 @@ history_show() { cat "$history_file" } +setup_tmpdir() { + if [ -z "$tmpdir" ]; then + tmpdir=`mktemp -d` + trap "rm -rf '$tmpdir'" EXIT + fi +} + + NODO="" inputxclip=0 do_screenshot=0 +make_qrcode=0 -while getopts "hnHSxs:" OPTION +while getopts "hnqHSxs:" OPTION do case $OPTION in h) usage exit ;; + q) + make_qrcode=1 + ;; n) NODO="echo" ;; @@ -136,9 +149,12 @@ do done shift $(($OPTIND - 1)) + +tmpdir="" + if [[ "$do_screenshot" -gt 0 ]]; then - img=`tempfile --suffix=.png --prefix=sshot` - trap "rm -f '$img'" EXIT + setup_tmpdir + img="$tmpdir/screenshot.png" import "$img" chmod a+r "$img" set dummy "$img" "$@" @@ -146,9 +162,12 @@ if [[ "$do_screenshot" -gt 0 ]]; then fi if [[ "$#" = 0 ]]; then - stdin=`tempfile` - trap "rm -f '$stdin'" EXIT - chmod a+r "$stdin" + setup_tmpdir + if [ "${name_stdin%-}" != "" ]; then + stdin="$tmpdir/$(basename "$name_stdin")" + else + stdin="$tmpdir/stdin" + fi if [ "$inputxclip" != 1 ] ; then echo "No files given on the command line, using stdin" >&2 @@ -165,15 +184,7 @@ if [[ "$#" = 0 ]]; then exit 1 fi fi - if [ "${name_stdin%-}" != "" ]; then - tmpdir=`mktemp -d` - target="$tmpdir/$(basename "$name_stdin")" - mv "$stdin" "$target" - trap "rm -f '$target' && rmdir '$tmpdir'" EXIT - set dummy "$target" - else - set dummy "$stdin" - fi + set dummy "$stdin" shift elif [ "$inputxclip" = 1 ] ; then echo "Ignoring -x because there are files on the command line" >&2 @@ -185,37 +196,46 @@ d_server="$d_date$d_random" rsync_args="--partial --recursive --compress --times" d_server_http_base=$( echo -n "$d_server" | uri_encode ) +base_uri="$base_http/$d_server_http_base/" +main_uri="$base_uri" +trail="" if [ "$#" = 1 ]; then - only_one=1 -else - only_one=0 - echo "$base_http/$d_server_http_base/" - if which xclip >/dev/null 2>&1; then - echo -n "$base_http/$d_server_http_base/" | xclip + if [ -d "$1" ]; then + trail="/" + else + main_uri="$base_uri$( echo -n "$(basename "$1")" | uri_encode )" fi +else + echo "$main_uri" fi publish_pre_invoke +if [ "$make_qrcode" -gt 0 ] ; then + if command -v qrencode >/dev/null 2>&1; then + setup_tmpdir + img="$tmpdir/.qr.png" + echo -n "$main_uri" | qrencode -s 5 -l H -o "$img" + $NODO rsync $rsync_args "$img" $base_rsync"/$d_server/" + echo "$base_uri"".qr.png" + main_uri="$base_uri"".qr.png" + else + echo >&2 "Warning: qrencode not found." + fi +fi + +if command -v xclip >/dev/null 2>&1; then + echo -n "$main_uri" | xclip +fi + + while [ "$#" -gt 0 ]; do file="$1" shift - uri="$base_http/$d_server_http_base/$( echo -n "`basename "$file"`" | uri_encode )" - - trail="" - if [ "$only_one" = 1 ]; then - if [ -d "$file" ]; then - trail="/" - uri="$base_http/$d_server_http_base/" - fi - if which xclip >/dev/null 2>&1; then - echo -n "$uri" | xclip - fi - fi - + uri="$base_uri""$( echo -n "`basename "$file"`" | uri_encode )" echo "$uri" history_append "$uri" @@ -224,4 +244,5 @@ while [ "$#" -gt 0 ]; do rsync_post_invoke done + publish_post_invoke |