|
1 | 1 | #!/bin/sh
|
2 |
| -if [ "$XDG_SESSION_TYPE" = "x11" ]; then |
3 |
| - # require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212) |
4 |
| - command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; } |
5 |
| - # write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file) |
6 |
| - filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-` |
7 |
| - if [ ! -n "$filePath" ] ;then |
8 |
| - if |
9 |
| - xclip -selection clipboard -target image/png -o >/dev/null 2>&1 |
10 |
| - then |
11 |
| - xclip -selection clipboard -target image/png -o >$1 2>/dev/null |
12 |
| - echo $1 |
| 2 | + |
| 3 | +if [ -z "$DISPLAY" ]; then |
| 4 | + echo "no support" >&2 |
| 5 | + exit 1 |
| 6 | +fi |
| 7 | + |
| 8 | +case "$XDG_SESSION_TYPE" in |
| 9 | +wayland) |
| 10 | + command -v wl-copy >/dev/null 2>&1 || { |
| 11 | + echo >&2 "no wl-clipboard" |
| 12 | + exit 1 |
| 13 | + } |
| 14 | + filePath=$(wl-copy -o 2>/dev/null | grep ^file:// | cut -c8-) |
| 15 | + if [ -z "$filePath" ]; then |
| 16 | + if |
| 17 | + wl-copy -t image/png image/png -o >"$1" 2>/dev/null |
| 18 | + then |
| 19 | + echo "$1" |
| 20 | + else |
| 21 | + rm -f "$1" |
| 22 | + echo "no image" |
| 23 | + fi |
13 | 24 | else
|
14 |
| - echo "no image" |
| 25 | + echo "$filePath" |
15 | 26 | fi
|
16 |
| - else |
17 |
| - echo $filePath |
18 |
| - fi |
19 |
| -elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then |
20 |
| - command -v wl-copy >/dev/null 2>&1 || { echo >&1 "no wl-clipboard"; exit 1; } |
21 |
| - filePath=`wl-copy -o 2>/dev/null | grep ^file:// | cut -c8-` |
22 |
| - if [ ! -n "$filePath" ] ;then |
23 |
| - if |
24 |
| - wl-copy -t image/png -o >/dev/null 2>&1 |
25 |
| - then |
26 |
| - wl-copy -t image/png image/png -o >$1 2>/dev/null |
27 |
| - echo $1 |
| 27 | + ;; |
| 28 | +x11 | tty) |
| 29 | + # require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212) |
| 30 | + command -v xclip >/dev/null 2>&1 || { |
| 31 | + echo >&2 "no xclip" |
| 32 | + exit 1 |
| 33 | + } |
| 34 | + # write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file) |
| 35 | + filePath=$(xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-) |
| 36 | + if [ -z "$filePath" ]; then |
| 37 | + if |
| 38 | + xclip -selection clipboard -target image/png -o >"$1" 2>/dev/null |
| 39 | + then |
| 40 | + echo "$1" |
| 41 | + else |
| 42 | + rm -f "$1" |
| 43 | + echo "no image" |
| 44 | + fi |
28 | 45 | else
|
29 |
| - echo "no image" |
| 46 | + echo "$filePath" |
30 | 47 | fi
|
31 |
| - else |
32 |
| - echo $filePath |
33 |
| - fi |
34 |
| -fi |
| 48 | + ;; |
| 49 | +esac |
0 commit comments