forked from CamilleScholtz/bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
punf
executable file
·162 lines (126 loc) · 2.97 KB
/
punf
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
#!/bin/fish
#
# punf - Upload files/scrots/urls to sr.ht (rip pomf & uguu)
# onodera, https://github.com/onodera-punpun
## CONFIGURATION
# Your sr.ht key
set key (cat $HOME/.srht)
# Log urls
set log false
# Set log location
set logfile $HOME/.punf
# Copy links to clipboard (requires xclip)
set clipboard true
# Send notification when upload is done (requires my notify script)
set notify true
# Open url in browser
set browser false
## FUNCTIONS
# This function sets $file to your clipboard contents
function clipboard
set -g uploadme /tmp/clipboard.txt
xclip -o > $uploadme
set -g word clipboard
end
# This function sets $file to a full screen scrot
function desktop
set -g uploadme /tmp/scrot.png
maim --hidecursor $uploadme
set -g word desktop
end
# This function sets $file to a file
function file
if test -f $argv
set -g uploadme $argv
else
echo "File not found."
exit 1
end
set -g word file
end
# This function sets $file to a selection stdin
function stdin
set -g uploadme /tmp/stdin.txt
cat /dev/stdin > $uploadme
set -g word stdin
end
# This function sets $file to a selection scrot
function selection
set -g uploadme /tmp/scrot.png
maim --hidecursor -s -b 3 -c 250,250,250 $uploadme ^ /dev/null
if test $status -ge 1
echo "Selection cancelled."
exit 1
end
set -g word selection
end
# This function sets $file to a url
function url
set type (echo $argv | rev | cut -d . -f 1 | rev)
set -g uploadme /tmp/url.$type
wget --quiet $argv -O $uploadme
set -g word url
end
# This function uploads the $file
function upload
set -g url (curl --silent -F key=$key -F file="@$uploadme" https://sr.ht/api/upload | grep -o -i "https://sr.ht/[a-z0-9._-]*")
end
# This function logs the url, copies the url to the clipboard, and/or opens the url in your browser
function feedback
# Copy url to clipboard
if test $clipboard = true -a $quiet = false
echo $url | xclip -selection primary
echo $url | xclip -selection clipboard
end
# Log url
if test $log = true -a $quiet = false
echo $url >> $logfile
end
# Open url in browser
if test $browser = true -a $quiet = false
$BROWSER $url
end
# Send notification
if test $notify = true -a $quiet = false
notify "Punfed $word: $url" &
end
# Send link
if test $quiet = true
echo $url
else
echo "Punfed $word: $url"
end
end
## EXECUTE
set quiet false
if test (count $argv) -ge 1
switch $argv[1]
case -h --help
echo -e "Usage: punf [options] [file/url]\n"
echo "options:"
echo " -c, --clipboard upload your clipboard as text"
echo " -s, --selection upload selection scrot"
echo " -q, --quiet disable all feedback (for scripts using punf)"
echo " -h, --help print help and exit"
exit 0
case -p -c --clipboard
clipboard
case -s --selection
selection
case -q --quiet
set quiet true
file $argv[2]
case "http*"
url $argv[1]
case "*"
file $argv[1]
end
else
if test -t 0
desktop
else
stdin
end
end
upload
feedback