build: set version to 0.5
[vis.git] / vis-clipboard
blob0ceed704d00992d9dd7e7fc25c58bd4b9f717dd1
1 #!/bin/sh
3 # Copyright (C) 2016 Richard Burke, ISC licensed
5 vc_fatal() {
6 echo "$@" >&2
7 exit 1
10 vc_usage() {
11 vc_fatal "`basename $0` [--usable|--copy|--paste]"
14 vc_determine_command() {
15 if [ -n "$DISPLAY" ]; then
16 for c in xclip xsel; do
17 if type "$c" >/dev/null 2>&1; then
18 echo "$c"
19 return 0
21 done
24 if type pbcopy >/dev/null 2>&1; then
25 echo 'mac'
26 return 0
29 if [ -c /dev/clipboard ]; then
30 echo 'cygwin'
31 return 0
34 return 1
37 vc_usable() {
38 if vc_determine_command >/dev/null 2>&1; then
39 exit 0
42 exit 1
45 vc_copy() {
46 COPY_CMD="`vc_determine_command 2>/dev/null`"
48 if [ $? -ne 0 ] || [ -z "$COPY_CMD" ]; then
49 vc_fatal 'System clipboard not supported'
52 vc_${COPY_CMD}_copy
54 exit $?
57 vc_paste() {
58 PASTE_CMD="`vc_determine_command 2>/dev/null`"
60 if [ $? -ne 0 ] || [ -z "$PASTE_CMD" ]; then
61 vc_fatal 'System clipboard not supported'
64 vc_${PASTE_CMD}_paste
66 exit $?
69 vc_xsel_copy() {
70 xsel -bi
73 vc_xsel_paste() {
74 xsel -bo
77 vc_xclip_copy() {
78 xclip -selection clipboard -i >/dev/null 2>&1
81 vc_xclip_paste() {
82 xclip -selection clipboard -o
85 vc_mac_copy() {
86 pbcopy
89 vc_mac_paste() {
90 pbpaste
93 vc_cygwin_copy() {
94 cat >/dev/clipboard
97 vc_cygwin_paste() {
98 cat /dev/clipboard
101 case "$1" in
102 --usable) vc_usable;;
103 --copy) vc_copy;;
104 --paste) vc_paste;;
105 *) ;;
106 esac
108 vc_usage