From cb0fd5f4f4dfd34890a6b576171bb7b75ab22e5f Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 5 Dec 2009 14:23:34 +0000 Subject: Implement publishing of stdout, the xclipboard, and put the urls into the xclipboard when done git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@428 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- publish | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/publish b/publish index 1782703..d5c6bce 100755 --- a/publish +++ b/publish @@ -38,13 +38,14 @@ history_lines=1000 usage() { cat << EOF -usage: $0 [ ...] +usage: $0 [ [ ...]] copy the file to a server an report the URL. OPTIONS: -h Show this message -s Show the history + -b Use input files' basenames on remote side (default when only one file is given) -n no-do. Just print what would have been done EOF } @@ -71,8 +72,9 @@ history_show() { } NODO="" +inputxclip=0 -while getopts "hns" OPTION +while getopts "hnsx" OPTION do case $OPTION in h) @@ -82,6 +84,9 @@ do n) NODO="echo" ;; + x) + inputxclip=1 + ;; s) if [ -r "$history_file" ]; then history_show @@ -100,8 +105,29 @@ done shift $(($OPTIND - 1)) if [[ "$#" = 0 ]]; then - echo "No files to copy" >&2 - exit 2 + stdin=`tempfile` + trap "rm -f '$stdin'" EXIT + chmod a+r "$stdin" + + if [ "$inputxclip" != 1 ] ; then + echo "No files given on the command line, using stdin" >&2 + cat > "$stdin" + else + if which xclip >/dev/null 2>&1; then + echo "Publishing x clipboard:" >&2 + xclip -o > "$stdin" + cat "$stdin" | sed -e 's#^#| #' + echo + echo "EOF" + else + echo "xclip not installed?" >&2 + exit 1 + fi + fi + set dummy "$stdin" + shift +elif [ "$inputxclip" = 1 ] ; then + echo "Ignoring -x because there are files on the command line" >&2 fi d_date=$(date +'%Y-%m-%d') @@ -116,23 +142,28 @@ if [ "$#" = 1 ]; then 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 + fi fi -for file in "$@"; do - uri="$base_http/$d_server_http_base/$( echo -n "$file" | uri_encode )" - echo "$uri" - history_append "$uri" -done while [ "$#" -gt 0 ]; do file="$1" shift - if [ -d "$file" ] && [ "$only_one" = 1 ]; then - trail="/" - else - trail="" + uri="$base_http/$d_server_http_base/$( echo -n "`basename $file`" | uri_encode )" + echo "$uri" + history_append "$uri" + + trail="" + if [ "$only_one" = 1 ]; then + if [ -d "$file" ]; then + trail="/" + fi + echo -n "$uri" | xclip fi + $NODO rsync $rsync_args "$file$trail" $base_rsync"/$d_server/" done -- cgit v1.2.3