-
Notifications
You must be signed in to change notification settings - Fork 21
/
thunar-upload-to-postimage.sh
executable file
·145 lines (127 loc) · 3.27 KB
/
thunar-upload-to-postimage.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
#!/usr/bin/env bash
#
# Upload a Picture to postimage.
#
# * Put this file into your home binary dir: ~/bin/
# * Make it executable: chmod +x
#
#
# Required Software:
# -------------------------
# * zenity
# * curl
# * gawk
#
#
# Thunar Integration
# ------------------------
#
# Command: ~/bin/thunar-upload-to-postimage.sh -f %f
# File Pattern: *
# Appear On: Image Files
#
#
# Usage:
# -------------------------
# thunar-upload-to-postimage.sh -f <filename> [-w width(int)] [-h height(int)] [-t window-title]
#
# required:
# -f input filename
#
# optional:
#
# -w (gui) width of window (e.g.: -w 800)
# default is 800
#
# -h (gui) height of window (e.g.: -h 240)
# default is 240
#
# -t (gui) window title
# default is filename
#
# Note:
# -------------------------
#
# Feel free to adjust/improve and commit back to:
# https://github.com/cytopia/thunar-custom-actions
#
usage() {
echo "$0 -f <filename> [-w width(int)] [-h height(int)] [-t window-title]"
echo
echo " required:"
echo " -f input filename"
echo
echo " optional:"
echo " -w (gui) width of window (e.g.: -w 800)"
echo " default is 800"
echo
echo " -h (gui) height of window (e.g.: -h 240)"
echo " default is 240"
echo
echo " -t (gui) window title"
echo " default is filename"
echo
}
while getopts ":f:cw:h:t:" i; do
case "${i}" in
f)
f="${OPTARG}"
;;
w)
w="${OPTARG}"
;;
h)
h="${OPTARG}"
;;
t)
t="${OPTARG}"
;;
*)
echo "Error - unrecognized option $1" 1>&2;
usage
;;
esac
done
shift $((OPTIND-1))
# Check if file is specified
if [ -z "${f}" ]; then
echo "Error - no file specified" 1>&2;
usage
exit 1
fi
# Check if zenity exists
if ! command -v zenity >/dev/null 2>&1 ; then
echo "Error - 'zenity' not found." 1>&2
exit 1
fi
# Check if curl exists
if ! command -v curl >/dev/null 2>&1 ; then
echo "Error - 'curl' not found." 1>&2
exit 1
fi
# Check if gawk exists
if ! command -v gawk >/dev/null 2>&1 ; then
echo "Error - 'gawk' not found." 1>&2
exit 1
fi
TITLE='Uploading to postimage.org...'$(basename "${f}")
TMPFILE=$(mktemp)
[ ! -z "${w##*[!0-9]*}" ] && WIDTH=$w || WIDTH=350
[ ! -z "${h##*[!0-9]*}" ] && HEIGHT=$h || HEIGHT=140
[ -n "${t}" ] && TITLE="${t}" || TITLE="Uploading to postimage: $(basename "${f}")"
curl -# -L -F "upload[]=@${f}" -o "${TMPFILE}" -F "adult=no" http://postimage.org 2>&1 | gawk -v RS='\r' '{print $2; fflush("") }' | zenity --width="${WIDTH}" --height="${HEIGHT}" --progress --title="${TITLE}" --text="${TITLE}" --auto-close --time-remaining
########################## gui output ###############################
[ -n "${t}" ] && TITLE=$t || TITLE="Uploaded to postimage: $(basename "${f}")"
TEXT=$(cat "${TMPFILE}")
rm "${TMPFILE}"
#TAG="$(echo "${TEXT}" | grep -Eo '<[a-z_]+>http' | sed -e "s/http//" | sed -e "s/<//" | sed -e "s/>//")"
#URL="$(echo "${TEXT}" | grep -Eo 'http[^<]+')"
ZTEXT="$(echo "${TEXT}" | grep -Eo 'http[^<]*' | grep "\[" | cut -d "]" -f1 | head -1)"
#urls=($URL)
#tags=($TAG)
#for ((i = 0; i < ${#urls[@]}; i++))
#do
# ZTEXT="$ZTEXT${tags[$i]}' <a href=\"${urls[$i]}\">${urls[$i]}</a>\n"
#done
zenity --width=${WIDTH} --height=${HEIGHT} --info --title "${TITLE}" --text="${ZTEXT}"
exit $?