Skip to content
This repository has been archived by the owner on Mar 7, 2022. It is now read-only.

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunelli committed Mar 24, 2019
2 parents c6945c2 + 0941c91 commit 1fb73a7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
19 changes: 4 additions & 15 deletions man/wl-clipboard-x11.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ are ignored by \fBwl-clipboard-x11\fP.

.RS 8
.TP
\fB-f\fP, \fB--filter\fP
\fB-f\fP, \fB-filter\fP

.TP
\fB-l\fP \fInum\fP, \fB--loops\fP \fInum\fP
\fB-l\fP \fInum\fP, \fB-loops\fP \fInum\fP
Will loop only once (see \fB--paste-once\fP in \fBwl-clipboard\fP)

.TP
\fB-t\fP \fItarget\fP, \fB--target\fP \fItarget\fP

.TP
\fB-d\fP \fIdisplayname\fP, \fB--display\fP \fIdisplayname\fP
\fB-d\fP \fIdisplayname\fP, \fB-display\fP \fIdisplayname\fP

.TP
\fB-selection\fP secondary
Expand All @@ -47,12 +45,6 @@ are ignored by \fBwl-clipboard-x11\fP.
\fBXSEL\fB

.RS 8
.TP
\fB-a\fP, \fB--append\fP

.TP
\fB-f\fP, \fB--follow\fP

.TP
\fB-d\fP, \fB--delete\fP
Will behave the same as \fB--clear\fP
Expand All @@ -69,9 +61,6 @@ Will behave the same as \fB--clear\fP
.TP
\fB--display\fP \fIdisplayname\fP

.TP
\fB-t\fP \fIms\fP, \fB--selectionTimeout\fP \fIms\fP

.TP
\fB-l\fP \fIfilename\fP, \fB--logfile\fP \fIfilename\fP

Expand Down
61 changes: 51 additions & 10 deletions src/wl-clipboard-x11
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
# Source: https://github.com/brunelli/wl-clipboard-x11
# License: GNU General Public License v3+

WL_COPY=$(which wl-copy) || exit 1
WL_PASTE=$(which wl-paste) || exit 1

CLIPBOARD_BACKEND="WL_CLIPBOARD"
CLIPBOARD_COMMAND="wl-copy"
CLIPBOARD_COMMAND="${WL_COPY}"
VERSION=2

calc() { awk "BEGIN{print $*}"; }

show_help() {
cat << EOF
Usage:
Expand Down Expand Up @@ -38,6 +43,10 @@ case "$(basename "$0")" in
xsel) CLIPBOARD_BACKEND="XSEL";;
esac

APPEND=0
FOLLOW=0
TIMEOUT=0
TIMEOUT_COMMAND=""
: $((COUNT = $#))
set -- "${@}" --

Expand All @@ -46,17 +55,19 @@ then
while [ $COUNT -ne 0 ]
do
case "$1" in
-i|-in) true;;
-i|-in) CLIPBOARD_COMMAND="${WL_COPY}";;
-o|-out)
CLIPBOARD_COMMAND="wl-paste"
CLIPBOARD_COMMAND="${WL_PASTE}"
set -- "${@}" "--no-newline"
;;
-f|-filter) true;;
-r|-rmlastnl) set -- "${@}" "--trim-newline";;
-l|-loops)
(($2)) && set -- "${@}" "--paste-once"
: $((COUNT = COUNT - 1))
shift 1
;;
-t|-target) set -- "${@}" "--type";;
-d|-display)
: $((COUNT = COUNT -1 ))
shift 1
Expand All @@ -82,6 +93,7 @@ then
-silent) shift;;
-quiet) set -- "${@}" "--foreground";;
-verbose) true;;
-noutf8) true;;
*) set -- "${@}" "$1";;
esac
: $((COUNT = COUNT - 1))
Expand All @@ -92,11 +104,11 @@ then
while [ $COUNT -ne 0 ]
do
case "$1" in
-a|--append) true;;
-f|--follow) true;;
-i|--input) true;;
-a|--append) APPEND=1;;
-f|--follow) FOLLOW=1;;
-i|--input) CLIPBOARD_COMMAND="${WL_COPY}";;
-o|--output)
CLIPBOARD_COMMAND="wl-paste"
CLIPBOARD_COMMAND="${WL_PASTE}"
set -- "${@}" "--no-newline"
;;
-c|--clear) set -- "${@}" "$1";;
Expand All @@ -111,6 +123,7 @@ then
shift 1
;;
-t|--selectionTimeout)
TIMEOUT=$(calc $2/1000)
: $((COUNT = COUNT - 1))
shift 1
;;
Expand Down Expand Up @@ -153,10 +166,38 @@ else
fi

shift
[ "$TIMEOUT" -ne 0 ] && TIMEOUT_COMMAND="timeout $TIMEOUT"

if [ $((FOLLOW)) -ne 0 ]
then
TEMP=$(mktemp -t ${CLIPBOARD_BACKEND}-buffer-XXXXXX)

trap "rm -f ${TEMP}; exit" EXIT
trap "" INT

if [ -p /dev/stdin ]
if [ "$TIMEOUT_COMMAND" ]
then
sleep ${TIMEOUT}; kill $$ &
fi

while dd count=1 of=${TEMP} status=none
do
{
[ $((APPEND)) -ne 0 ] && ${WL_PASTE} -n 2> /dev/null
cat ${TEMP}
} |
${WL_COPY} "${@}"

[ -s ${TEMP} ] || break
APPEND=1
done
elif [ $((APPEND)) -ne 0 ]
then
cat | ${CLIPBOARD_COMMAND} "${@}"
{
${WL_PASTE} -n 2> /dev/null
cat
} |
${TIMEOUT_COMMAND} ${WL_COPY} "${@}"
else
${CLIPBOARD_COMMAND} "${@}"
${TIMEOUT_COMMAND} ${CLIPBOARD_COMMAND} "${@}"
fi

0 comments on commit 1fb73a7

Please sign in to comment.