-
Notifications
You must be signed in to change notification settings - Fork 1
/
yadshot.sh
executable file
·509 lines (496 loc) · 20.2 KB
/
yadshot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
#!/bin/bash
# Title: yadshot
# Author: simoniz0r
# Description: Uses yad to provide a simple GUI for using slop to capture screenshots using Imagemagick's import
# License: GPL v2 Only
# Dependencies: coreutils, slop, imagemagick, yad, xclip, curl, grabc (optional - for use with color picker)
# export running directory variables for use later
export YADSHOT_PATH="$(readlink -f $0)"
export RUNNING_DIR="$(dirname $(readlink -f $0))"
if [ -f "/usr/share/icons/hicolor/scalable/apps/yadshot.svg" ]; then
export ICON_PATH="/usr/share/icons/hicolor/scalable/apps/yadshot.svg"
else
export ICON_PATH="gtk-fullscreen"
fi
# check for dependencies
if [ ! -f "$RUNNING_DIR/filebiner" ]; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)filebiner is missing!$(tput sgr0)"
fi
if ! type curl >/dev/null 2>&1; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)curl is not installed!$(tput sgr0)"
fi
if ! type import >/dev/null 2>&1 && [ ! -f "$RUNNING_DIR/ImageMagick" ] && ! type ffmpeg >/dev/null 2>&1; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)imagemagick or ffmpeg not installed!$(tput sgr0)"
fi
if ! type yad >/dev/null 2>&1; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)yad is not installed!$(tput sgr0)"
fi
if ! type xclip >/dev/null 2>&1; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)xclip is not installed!$(tput sgr0)"
fi
if ! type slop >/dev/null 2>&1; then
MISSING_DEPS="TRUE"
echo "$(tput setaf 1)slop is not installed!$(tput sgr0)"
fi
if [ "$MISSING_DEPS" = "TRUE" ]; then
echo "$(tput setaf 1)Missing one or more packages required to run; exiting...$(tput sgr0)"
exit 1
fi
# set default variables
SS_NAME="yadshot-$(date +'%s').png"
SELECTION="TRUE"
DECORATIONS="TRUE"
COPYONCAP="TRUE"
SS_DELAY=0
if type ffmpeg >/dev/null 2>&1; then
export YSHOT_IMAGE_PLUGIN="ffmpeg"
elif type import >/dev/null 2>&1 || [ -f "$RUNNING_DIR/ImageMagick" ]; then
export YSHOT_IMAGE_PLUGIN="ImageMagick"
else
export YSHOT_IMAGE_PLUGIN="Unknown"
fi
# create yadshot config dir
if [ ! -d "$HOME/.config/yadshot" ]; then
mkdir -p ~/.config/yadshot
echo "SELECTION="\"$SELECTION\""" > ~/.config/yadshot/yadshot.conf
echo "DECORATIONS="\"$DECORATIONS\""" >> ~/.config/yadshot/yadshot.conf
echo "SS_DELAY="\"$SS_DELAY\""" >> ~/.config/yadshot/yadshot.conf
echo "YSHOT_IMAGE_PLUGIN="\"$YSHOT_IMAGE_PLUGIN\""" >> ~/.config/yadshot/yadshot.conf
fi
# source yadshot config file
[ -f "$HOME/.config/yadshot/yadshot.conf" ] && . ~/.config/yadshot/yadshot.conf
if [ ! -d "$HOME/.config/yadshot/plugins" ]; then
mkdir -p ~/.config/yadshot/plugins
echo "SELECTION="\"$SELECTION\""" > ~/.config/yadshot/yadshot.conf
echo "DECORATIONS="\"$DECORATIONS\""" >> ~/.config/yadshot/yadshot.conf
echo "SS_DELAY="\"$SS_DELAY\""" >> ~/.config/yadshot/yadshot.conf
echo "YSHOT_IMAGE_PLUGIN="\"$YSHOT_IMAGE_PLUGIN\""" >> ~/.config/yadshot/yadshot.conf
fi
# create ~/Pictures if it does not exist
if [ ! -d "$HOME/Pictures" ]; then
mkdir -p "$HOME"/Pictures
fi
# add handler to manage process shutdown
function on_exit() {
echo "quit" >&3
rm -f $PIPE
exit 0
}
export -f on_exit
# add handler for tray icon left click
function on_click() {
"$YADSHOT_PATH"
exit 0
}
export -f on_click
# function for uploading file from tray
function filebin_file() {
"$YADSHOT_PATH" -f
exit 0
}
export -f filebin_file
# function for uploading paste from tray
function filebin_paste() {
"$YADSHOT_PATH" -p
exit 0
}
export -f filebin_paste
# function for capturing screenshot from tray
function yadshot_capture() {
"$YADSHOT_PATH" -s
exit 0
}
export -f yadshot_capture
# function for launching color picker from tray
function yadshotcolor() {
if type grabc > /dev/null 2>&1; then
COLOR_SELECTION="$(yad --window-icon="$ICON_PATH" --center --title="yadshot" --color --init-color="$(grabc | head -n 1)" --mode=hex)"
else
COLOR_SELECTION="$(yad --window-icon="$ICON_PATH" --center --title="yadshot" --color --mode=hex)"
fi
case $? in
0)
echo -n "$COLOR_SELECTION" | xclip -i -selection clipboard
exit 0
;;
*)
exit 0
;;
esac
}
export -f yadshotcolor
# function to view upload list from tray
function upload_list() {
LIST_ITEM="$("$RUNNING_DIR"/filebiner ls | tail -n +2 | yad --window-icon="$ICON_PATH" --borders=10 --center --list --height 600 --width 800 --title="yadshot" --text="\nDouble click an item to copy it to the clipboard." --dclick-action="bash -c 'echo -n %s | xclip -i -selection clipboard'" --separator="" --column="Uploads" --button="Delete Selected"\!gtk-delete:0 --button="Close"\!gtk-cancel:1)"
case $? in
1)
sleep 0
;;
0)
local FILE_NAME="$(echo "$LIST_ITEM" | rev | cut -f2- -d'?' | cut -f1 -d'/' | rev)"
filebiner -y rm -n "$FILE_NAME"
case $? in
1) echo "Failed to remove '$FILE_NAME' from Filebin!" | yad --window-icon="$ICON_PATH" --borders=20 --center --text-info --wrap --title="yadshot" --button=gtk-ok;;
0) echo "'$FILE_NAME' has been removed from Filebin!" | yad --window-icon="$ICON_PATH" --borders=20 --center --text-info --wrap --title="yadshot" --button=gtk-ok;;
esac
"$YADSHOT_PATH" -l
;;
esac
}
export -f upload_list
# create the notification icon
function yadshottray() {
trap on_exit EXIT
# create a FIFO file, used to manage the I/O redirection from shell
PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
# attach a file descriptor to the file
exec 3<> $PIPE
yad --window-icon="gtk-zoom-fit" --notification --listen --image="gtk-zoom-fit" --text="yadshot" --command="bash -c on_click" --item-separator="," \
--menu="New Screenshot,bash -c yadshot_capture,gtk-new|Upload File,bash -c filebin_file,gtk-go-up|Upload Paste,bash -c filebin_paste,gtk-copy|Color Picker,bash -c yadshotcolor,gtk-color-picker|View Upload List,bash -c upload_list,gtk-edit|Quit,quit,gtk-cancel" <&3
}
export -f yadshottray
# save settings to yadshot config dir
function yadshotsavesettings() {
echo "SELECTION="\"$SELECTION\""" > ~/.config/yadshot/yadshot.conf
echo "DECORATIONS="\"$DECORATIONS\""" >> ~/.config/yadshot/yadshot.conf
echo "COPYONCAP="\"$COPYONCAP\""" >> ~/.config/yadshot/yadshot.conf
echo "SS_DELAY="\"$SS_DELAY\""" >> ~/.config/yadshot/yadshot.conf
echo "YSHOT_IMAGE_PLUGIN="\"$YSHOT_IMAGE_PLUGIN\""" >> ~/.config/yadshot/yadshot.conf
}
export -f yadshotsavesettings
# change yadshot's settings
function yadshotsettings() {
. ~/.config/yadshot/yadshot.conf
if [ $(dir -C -w 1 $HOME/.config/yadshot/plugins | wc -l) -gt 0 ]; then
YSHOT_PLUGIN_LIST="$(dir -C -w 1 $HOME/.config/yadshot/plugins | tr '\n' ',' | rev | cut -f2- -d',' | rev)"
fi
if type ffmpeg >/dev/null 2>&1; then
YSHOT_PLUGIN_LIST="ffmpeg,$YSHOT_PLUGIN_LIST"
fi
if type import >/dev/null 2>&1 || [ -f "$RUNNING_DIR/ImageMagick" ]; then
YSHOT_PLUGIN_LIST="ImageMagick,$YSHOT_PLUGIN_LIST"
fi
YSHOT_PLUGIN_LIST="$(echo $YSHOT_PLUGIN_LIST | tr ',' '\n' | grep -vw "$YSHOT_IMAGE_PLUGIN" | sed '/^$/d' | tr '\n' ',')"
YSHOT_PLUGIN_LIST="$(echo $YSHOT_IMAGE_PLUGIN,$YSHOT_PLUGIN_LIST | rev | cut -f2- -d',' | rev)"
OUTPUT="$(yad --window-icon="$ICON_PATH" --center --title="yadshot" --height=200 --columns=1 --form --no-escape --item-separator="," --separator="," --borders="10" \
--field="Capture selection":CHK "$SELECTION" --field="Capture decorations":CHK "$DECORATIONS" --field="Copy screenshot to clipboard on capture":CHK "$COPYONCAP" --field="Delay before capture":NUM "$SS_DELAY!0..120" \
--field="Image capture plugin":CB "$YSHOT_PLUGIN_LIST" --button="gtk-ok")"
SELECTION="$(echo $OUTPUT | cut -f1 -d",")"
DECORATIONS="$(echo $OUTPUT | cut -f2 -d",")"
COPYONCAP="$(echo $OUTPUT | cut -f3 -d",")"
SS_DELAY="$(echo $OUTPUT | cut -f4 -d",")"
YSHOT_IMAGE_PLUGIN="$(echo $OUTPUT | cut -f5 -d",")"
yadshotsavesettings
}
export -f yadshotsettings
# upload screenshots and files to Filebin.net; set FAILED=1 if upload fails
function yadshotupload() {
echo -n "" | xclip -i -selection clipboard
"$RUNNING_DIR"/filebiner up -f "$1"
FILE_URL="$(xclip -o -selection clipboard)"
if [[ -z "$FILE_URL" ]]; then
echo 'error uploading file!\n'
FAILED=1
yad --window-icon="$ICON_PATH" --center --error --title="yadshot" --text="Failed to upload '$1'!"
else
FAILED=0
rm -f "$HOME/Pictures/$SS_NAME"
echo "$FILE_URL" | yad --window-icon="$ICON_PATH" --center --height=200 --width=300 --borders=20 --text-info --wrap --show-uri --uri-color="yellow" --title="yadshot" --button="Back"\!gtk-ok:0 --button="Close"\!gtk-cancel:1
case $? in
1)
rm -f /tmp/"$SS_NAME"
exit 0
;;
esac
fi
}
# detect which image capture plugin to use
function yadshotcaptureselect() {
case "$YSHOT_IMAGE_PLUGIN" in
ImageMagick)
yadshotcapture
;;
ffmpeg)
yadshotcaptureffmpeg
;;
*)
if [ -f "$HOME/.config/yadshot/plugins/$YSHOT_IMAGE_PLUGIN" ]; then
source ~/.config/yadshot/plugins/"$YSHOT_IMAGE_PLUGIN"
yadshotcaptureplugin
else
yadshotcapture
fi
;;
esac
}
# capture screenshot using slop and imagemagick
function yadshotcapture() {
. ~/.config/yadshot/yadshot.conf
if [ "$SELECTION" = "FALSE" ]; then
if [ $SS_DELAY -eq 0 ]; then
SS_DELAY=0.5
fi
sleep "$SS_DELAY"
if [ -f "$RUNNING_DIR/ImageMagick" ]; then
"$RUNNING_DIR"/ImageMagick import -window root /tmp/"$SS_NAME"
else
import -window root /tmp/"$SS_NAME"
fi
elif [ "$SELECTION" = "TRUE" ] && [ "$DECORATIONS" = "TRUE" ]; then
read -r G < <(slop --nokeyboard -c 0,119,255,0.34 -f "%g")
sleep "$SS_DELAY"
if [ -f "$RUNNING_DIR/ImageMagick" ]; then
"$RUNNING_DIR"/ImageMagick import -window root -crop $G /tmp/"$SS_NAME"
else
import -window root -crop $G /tmp/"$SS_NAME"
fi
elif [ "$SELECTION" = "TRUE" ] && [ "$DECORATIONS" = "FALSE" ]; then
read -r G < <(slop --nokeyboard -nc 0,119,255,0.34 -f "%g")
sleep "$SS_DELAY"
if [ -f "$RUNNING_DIR/ImageMagick" ]; then
"$RUNNING_DIR"/ImageMagick import -window root -crop $G /tmp/"$SS_NAME"
else
import -window root -crop $G /tmp/"$SS_NAME"
fi
fi
}
# capture screenshot using slop and ffmpeg
function yadshotcaptureffmpeg() {
. ~/.config/yadshot/yadshot.conf
if [ "$SELECTION" = "FALSE" ]; then
if [ $SS_DELAY -eq 0 ]; then
SS_DELAY=0.5
fi
sleep "$SS_DELAY"
W=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f2 -d" ")
H=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f4 -d" ")
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0 -vframes 1 /tmp/"$SS_NAME" > /dev/null 2>&1
elif [ "$SELECTION" = "TRUE" ] && [ "$DECORATIONS" = "TRUE" ]; then
MAXW=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f2 -d" ")
MAXH=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f4 -d" ")
read -r X Y W H G ID < <(slop --nokeyboard -c 0,119,255,0.34 -f "%x %y %w %h %g %i")
[ $W -eq 1921 ] && W=1920
[ $W -gt $MAXW ] && W=$MAXW
[ $H -gt $MAXH ] && H=$MAXH
[ $X -gt $MAXW ] && X=$MAXW
[ $Y -gt $MAXH ] && Y=$MAXH
sleep "$SS_DELAY"
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -vframes 1 /tmp/"$SS_NAME" # > /dev/null 2>&1
elif [ "$SELECTION" = "TRUE" ] && [ "$DECORATIONS" = "FALSE" ]; then
MAXW=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f2 -d" ")
MAXH=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f4 -d" ")
read -r X Y W H G ID < <(slop --nokeyboard -nc 0,119,255,0.34 -f "%x %y %w %h %g %i")
[ $W -gt $MAXW ] && W=$MAXW
[ $H -gt $MAXH ] && H=$MAXH
[ $X -gt $MAXW ] && X=$MAXW
[ $Y -gt $MAXH ] && Y=$MAXH
sleep "$SS_DELAY"
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -vframes 1 /tmp/"$SS_NAME" > /dev/null 2>&1
fi
}
# display screenshot; resize it first if it's too large to be displayed on user's screen
function displayss() {
. ~/.config/yadshot/yadshot.conf
if [ ! -f "/tmp/$SS_NAME" ]; then
echo "Failed to capture screenshot!" | yad --window-icon="$ICON_PATH" --center --height=200 --width=300 --borders=10 --text-info --wrap --title="yadshot" --button=gtk-ok
exit 1
fi
if [ "$COPYONCAP" = "TRUE" ]; then
xclip -selection clipboard -t image/png -i < /tmp/"$SS_NAME"
fi
WSCREEN_RES=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f2 -d" " | awk '{print $1 * .75}' | cut -f1 -d'.')
HSCREEN_RES=$(xrandr | grep 'current' | cut -f2 -d"," | sed 's:current ::g' | cut -f4 -d" " | awk '{print $1 * .75}' | cut -f1 -d'.')
WSIZE=$(file /tmp/$SS_NAME | cut -f2 -d"," | cut -f2 -d" " | cut -f1 -d'.')
HSIZE=$(file /tmp/$SS_NAME | cut -f2 -d"," | cut -f4 -d" " | cut -f1 -d'.')
WSIZEYAD=$(($WSIZE+75))
HSIZEYAD=$(($HSIZE+75))
if [ $WSCREEN_RES -le $WSIZE ] || [ $HSCREEN_RES -le $HSIZE ]; then
yad --window-icon="$ICON_PATH" --center --picture --size=fit --width=$WSCREEN_RES --height=$HSCREEN_RES --no-escape --filename="/tmp/$SS_NAME" --image-on-top --buttons-layout="edge" --title="yadshot" --separator="," --borders="10" \
--button="Close"\!gtk-cancel:1 --button="Main Menu"\!gtk-home:2 --button="Copy to Clipboard"\!gtk-paste:3 --button="Upload to Filebin"\!gtk-go-up:4 --button=gtk-save:5 --button="New Screenshot"\!gtk-new:0
else
yad --window-icon="$ICON_PATH" --center --picture --size=orig --width=$WSIZEYAD --height=$HSIZEYAD --no-escape --filename="/tmp/$SS_NAME" --image-on-top --buttons-layout="edge" --title="yadshot" --separator="," --borders="10" \
--button="Close"\!gtk-cancel:1 --button="Main Menu"\!gtk-home:2 --button="Copy to Clipboard"\!gtk-paste:3 --button="Upload to Filebin"\!gtk-go-up:4 --button=gtk-save:5 --button="New Screenshot"\!gtk-new:0
fi
BUTTON_PRESSED="$?"
buttonpressed
}
# detect button pressed from displayss function and run relevant tasks
function buttonpressed() {
case $BUTTON_PRESSED in
1)
rm -f /tmp/"$SS_NAME"
exit 0
;;
2)
"$YADSHOT_PATH"
;;
3)
xclip -selection clipboard -t image/png -i < /tmp/"$SS_NAME"
displayss
;;
4)
cp /tmp/"$SS_NAME" "$HOME"/Pictures/"$SS_NAME"
yadshotupload "$HOME/Pictures/$SS_NAME"
displayss
;;
5)
SAVE_DIR=$(yad --window-icon="$ICON_PATH" --center --file --save --confirm-overwrite --title="yadshot" --width=800 --height=600 --text="Save $SS_NAME as...")
cp /tmp/"$SS_NAME" "$SAVE_DIR"
displayss
;;
0)
rm -f /tmp/"$SS_NAME"
yadshotsettings
"$YADSHOT_PATH" -c
;;
esac
}
# upload paste from clipboard to Filebin.net with optional syntax
function yadshotpaste() {
echo -e "$(xclip -o -selection clipboard)" > /tmp/yadshotpaste.txt
PASTE_CONTENT="$(yad --window-icon="$ICON_PATH" --center --title="yadshot" --height=600 --width=800 --text-info --wrap --filename="/tmp/yadshotpaste.txt" --editable --borders="10" --button="Cancel"\!gtk-cancel:1 --button="Ok"\!gtk-ok:0)"
case $? in
0)
echo -e "$PASTE_CONTENT" > /tmp/yadshotpaste.txt
;;
*)
rm -f /tmp/yadshotpaste.txt
exit 0
;;
esac
echo -n "" | xclip -i -selection clipboard
"$RUNNING_DIR"/filebiner up -f /tmp/yadshotpaste.txt
PASTE_URL="$(xclip -o -selection clipboard)"
rm -f /tmp/yadshotpaste.txt
if [[ -z "$PASTE_URL" ]]; then
echo "Failed to upload paste!"| yad --window-icon="$ICON_PATH" --center --height=200 --width=300 --borders=20 --text-info --wrap --title="yadshot" --button=gtk-ok
exit 1
else
echo "$PASTE_URL" | yad --window-icon="$ICON_PATH" --center --height=200 --width=300 --borders=20 --text-info --wrap --show-uri --uri-color="yellow" --title="yadshot" --button=gtk-ok
fi
}
# get input from stdin and upload to Filebin.net
function yadshotpastepipe() {
cat - > /tmp/yadshotpaste.txt
echo -n "" | xclip -i -selection clipboard
"$RUNNING_DIR"/filebiner up -f /tmp/yadshotpaste.txt
PASTE_URL="$(xclip -o -selection clipboard)"
rm -f /tmp/yadshotpaste.txt
if [[ -z "$PASTE_URL" ]]; then
echo "Failed to upload paste!" | yad --center --height=200 --width=300 --borders=20 --text-info --wrap --title="yadshot" --button=gtk-ok
exit 1
else
echo "$PASTE_URL"| yad --center --height=200 --width=300 --borders=20 --text-info --wrap --show-uri --uri-color="yellow" --title="yadshot" --button=gtk-ok
fi
}
# select a file to upload to Filebin.net
function yadshotfileselect() {
FILE="$(yad --window-icon="$ICON_PATH" --file $PWD --center --add-preview --title=yadshot --height 600 --width 800)"
case $? in
0)
yadshotupload "$FILE"
;;
*)
exit 0
;;
esac
}
# main yadshot window
function startfunc() {
yad --window-icon="$ICON_PATH" --center --title="yadshot" --height=200 --width=325 --form --no-escape --separator="" --button-layout="center" \
--borders="20" --columns="1" --button="New Screenshot"\!gtk-add:0 --button="Close"\!gtk-cancel:1 \
--field="Upload File!gtk-go-up":FBTN "$YADSHOT_PATH -f" --field="Upload Paste!gtk-copy":FBTN "$YADSHOT_PATH -p" \
--field="Color Picker!gtk-color-picker":FBTN "$YADSHOT_PATH -C" --field="View Upload List!gtk-edit":FBTN "bash -c upload_list" \
--field="Settings!gtk-preferences":FBTN "bash -c yadshotsettings" --field="Start Tray App!gtk-go-down":FBTN "bash -c yadshottray"
case $? in
0)
yadshotsettings
yadshotcaptureselect
displayss
exit 0
;;
*)
exit 0
;;
esac
}
# help function
function yadshothelp() {
printf '%s\n' "yadshot v0.2.05
yadshot provides a GUI frontend for taking screenshots with
ImageMagick/slop or ffmpeg/slop. yadshot can upload screenshots,
files, and pastes to Filebin.net.
Arguments:
--capture, -c Capture a screenshot. Screenshot will be shown after capture with
options to copy to clipboard, upload, or save.
--settings, -s Show screenshot settings before capturing a screenshot.
--paste, -p Upload a paste from your clipboard to Filebin.net. Text may also be piped in from stdin.
--file, -f Open the file chooser and upload a file to Filebin.net
--list, -l List files uploaded to Filebin.net
--color, -C Open color picker. Color will be copied to clipboard if 'Ok' is pressed.
--tray, -t Open a system tray app for quick access to yadshot.
If no argument is passed, yadshot's main menu will be shown.
"
}
# detect arguments
case $1 in
-h|--help)
yadshothelp
exit 0
;;
# use 'while IFS= read line; do' to check if data piped in from stdin otherwise display file chooser
-p|--paste)
shift
for ARG in "$@"; do
case "$ARG" in
-s|--syntax)
shift
PASTE_SYNTAX=".$1"
shift
;;
esac
done
if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then
yadshotpastepipe
else
yadshotpaste
exit 0
fi
;;
-f|--file)
yadshotfileselect
exit 0
;;
-l|--list)
upload_list
exit 0
;;
-s|--settings)
yadshotsettings
yadshotcaptureselect
displayss
exit 0
;;
-c|--capture)
yadshotcaptureselect
displayss
exit 0
;;
-C|--color)
yadshotcolor
exit 0
;;
-t|--tray)
yadshottray &
exit 0
;;
*)
startfunc
;;
esac