From 52f3ffaff5437a2f8a3786ededb43a3fee7fdcca Mon Sep 17 00:00:00 2001 From: Bo Ørsted Andresen Date: Wed, 28 Feb 2007 12:23:58 +0000 Subject: Add --xcut. Make sure add_to_clipboard() and get_from_clipboard() are used if defined by the user. Otherwise print instructions to define it when --xcut is used. --- wgetpaste | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/wgetpaste b/wgetpaste index 8854aa1..941fde7 100755 --- a/wgetpaste +++ b/wgetpaste @@ -34,7 +34,14 @@ escape() { ### defaults # The following defaults can be overridden in either /etc/wgetpaste or ~/.wgetpaste. -# Only those three variables should be set in those files. +# Only those four variables should be set in those files. +# +# If add_to_clipboard() is defined as a function in one of those files it will be called with +# the url where your paste can be seen as an argument. You may use xclip, xcut, klipper or +# whatever your window manager provides for adding it to your clipboard. +# +# Likewise if get_from_clipboard() is defined as a funciont in one of those files it will be +# called to retrieve input from your clipboard when --xcut is used. [[ -f /etc/wgetpaste ]] && . /etc/wgetpaste [[ -f ~/.wgetpaste ]] && . ~/.wgetpaste DEFAULT_NICK="${DEFAULT_NICK:-$(whoami)}" @@ -55,6 +62,8 @@ show_usage() { echo " -S, --list-services list supported pastebin services" echo " -L, --list-languages list languages supported by the specified service" echo + echo " -x, --xcut read input from clipboard (requires configuration)" + echo echo " -v, --verbose show wget stderr output if no url is received" echo " --debug be *very* verbose (implies -v)" echo @@ -307,7 +316,25 @@ if [[ ! -r "${SOURCE}" ]]; then exit 1 fi -INPUT="$(escape "$(<${SOURCE})")" +# read input +if [[ ${XCUT} ]]; then + if [[ "$(type -t get_from_clipboard)" == "function" ]]; then + INPUT="$(escape "$(get_from_clipboard)")" + else + echo "You need to define get_from_clipboard() in /etc/wgetpaste or ~/.wgetpaste to use --xcut." 1>&2 + echo "If you want to use e.g. xclip simply emerge xclip and define it like this:" 1>&2 + echo 1>&2 + echo -e "get_from_clipboard() {\n xclip -o\n}\n" 1>&2 + echo "Likewise if you want the resulting url stored in your clipboard using e.g. xclip" 1>&2 + echo "define it like this:" 1>&2 + echo 1>&2 + echo -e "add_to_clipboard() {\n xclip \"\$*\"\n}\n" 1>&2 + echo "Use whatever your window manager provides to alter your clipboard." 1>&2 + exit 1 + fi +else + INPUT="$(escape "$(<${SOURCE})")" +fi [[ -z "${INPUT}" ]] && die "No input read. Nothing to paste. Aborting." # print a friendly warning if the size makes failure predictable for the specified pastebin service. @@ -358,5 +385,10 @@ if [[ -z "${URL}" ]]; then exit 1 fi +# add_to_clipboard() may be defined in /etc/wgetpaste or ~/.wgetpaste and can be used to add +# ${URL} to your clipboard using xclip, xcut, klipper or whatever your window manager provides +# for that task. +[[ "$(type -t add_to_clipboard)" == "function" ]] && add_to_clipboard "${URL}" + echo "Your paste can be seen here: ${URL}" exit 0 -- cgit v1.2.3