forked from sunmockyang/puush-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuush
executable file
·133 lines (114 loc) · 3.2 KB
/
puush
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
#!/bin/bash
# Set API Key here
PUUSH_API_KEY=""
# Puush for Ubuntu/linux
# Owner : Sunmock Yang
# www.sunmock.com
# May 2014
#
# Dependencies:
# - gnome-screenshot
# - curl
# - zenity
# - xclip
# - notify-send
#
# Licence : Beerware
#
# Instructions:
# - Add your puush API key to PUUSH_API_KEY (You can find your API key at http://puush.me/account/settings)
# - Place this file wherever you want (/usr/local/bin)
# - Set up keyboard shortcuts within linux (in Ubuntu it's system settings > keyboard > keyboard shortcuts > custom shortcuts)
#
# command description (recommended keyboard shortcut)
# ---------------------------------------------------------------
# puush -c puush window (Ctrl + Shift + 2/@)
# puush -a puush desktop (Ctrl + Shift + 3/#)
# puush -b area puush (Ctrl + Shift + 4/$)
# puush -d file upload (Ctrl + Shift + U)
#
#
# Notes:
# - Link(s) will be copied into clipboard and appear in notifications
# - puush curl upload code borrowed from online sources
# Usage: puushFile [fileName]
function puushFile ()
{
if [ -z "$1" ]; then
echo "No file specified"
exit 1
elif [ ! -f "$1" ]; then
echo "Puush cancelled"
exit 1
fi
fileURL=`curl "https://puush.me/api/up" -# -F "k=$PUUSH_API_KEY" -F "z=waifu" -F "f=@$1" | sed -E 's/^.+,(.+),.+,.+$/\1\n/'`
if [ ! -z "$fileURL" ]; then
#Copy link to clipboard, show notification
printf $fileURL | xclip -selection "clipboard"
notify-send -i "$( cd "$( dirname "$0" )" && pwd )/icon.png" -t 2000 "puush complete!" "$fileURL"
fi
}
function helpText ()
{
printf "_____________ puush for linux _____________\n"
printf "Created by Sunmock Yang using the puush api\n"
printf "\n"
printf "Usage:\n"
printf " puush [OPTIONS] [PATH]\n"
printf "\n"
printf "OPTIONS:\n"
printf " -a puush entire desktop\n"
printf " -b select area to puush\n"
printf " -c puush current window\n"
printf " -d puush specific file (opens file dialog)\n"
printf "\n"
printf " --help,-h show this page\n"
printf "\n"
printf "PATH:\n"
printf " PATH optional: path of file to puush\n"
}
function generateFileName () { echo "/tmp/puush-linux ($(date +"%Y-%m-%d at %I.%M.%S")).png"; }
if [ -z "$PUUSH_API_KEY" ]; then
echo "Set the variable PUUSH_API_KEY in $0"
echo "You can find your API key at http://puush.me/account/settings"
notify-send -i "$( cd "$( dirname "$0" )" && pwd )/icon.png" "Set the variable PUUSH_API_KEY in $0" "You can find your API key at http://puush.me/account/settings"
exit 1
elif [ -z "$1" ]; then
echo "No file entered."
helpText
exit 1
fi
#Get file to puush and puush it
case "$1" in
-a)
echo "Whole Desktop"
fileName=$(generateFileName)
gnome-screenshot -f "$fileName"
puushFile "$fileName"
;;
-b)
echo "Area"
fileName=$(generateFileName)
gnome-screenshot -a -f "$fileName"
puushFile "$fileName"
;;
-c)
echo "Window"
fileName=$(generateFileName)
gnome-screenshot -w -f "$fileName"
puushFile "$fileName"
;;
-d)
echo "File Upload"
fileName=`zenity --file-selection`
puushFile "$fileName"
;;
-h|--help)
helpText
exit 0
;;
*)
echo "Upload $1"
puushFile "$1"
;;
esac