-
Notifications
You must be signed in to change notification settings - Fork 1
/
qwq.sh
executable file
·78 lines (60 loc) · 1.92 KB
/
qwq.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
#!/bin/bash
# -----------------------------------
# - qwq, light owo client for macos -
# -----------------------------------
# (c) slice 2018
if [[ ! -f "$HOME/.config/qwq-token" ]]; then
echo "Error: ~/.config/qwq-token not found."
fi
# --- configurables
# directory in which to store screenshots
SCREENSHOT_DIRECTORY="$HOME/Pictures/screenshots"
# your owo token, read from ~/.config/qwq-token
TOKEN=$(tr -d "\n" < ~/.config/qwq-token)
# path to jq
JQ_PATH=/usr/local/bin/jq
# file path when screenshotting
DATE_FORMAT="%m-%d-%Y-%I:%M:%S-%p"
SAVE_PATH="$SCREENSHOT_DIRECTORY/$(date +$DATE_FORMAT).png"
# vanity url to output
VANITY="owo.sh"
USER_AGENT="qwq.sh (https://github.com/slice/qwq)"
# ---
if [[ $# != 0 ]]; then
file=$1
echo "Uploading..."
OWO_OUTPUT=$(curl -s -F "files[]=@\"$file\"" https://api.awau.moe/upload/pomf?key="$TOKEN" \
-H "User-Agent: $USER_AGENT")
echo "Uploaded! $OWO_OUTPUT"
FILE=$(echo "$OWO_OUTPUT" | $JQ_PATH -r ".files[0].url")
URL="https://$VANITY/$FILE"
echo -n "$URL" | pbcopy
echo "Copied to clipboard: $URL"
exit 0
fi
mkdir -p "$SCREENSHOT_DIRECTORY"
# screencap
screencapture -di "$SAVE_PATH"
# detect cancellation
if [[ "$?" == "1" ]]; then
echo "Screencapture cancelled."
exit 1
fi
echo "Saved to: $SAVE_PATH"
if [[ "$(uname)" == *"Darwin"* ]] && [[ -x /usr/local/bin/convert ]]; then
# assume a 2xDPI display, and resize down to 65%
/usr/local/bin/convert "$SAVE_PATH" -resize 65% "$SAVE_PATH"
fi
# upload
echo "Uploading..."
OWO_OUTPUT=$(curl -s -F "files[]=@\"$SAVE_PATH\";type=image/png" https://api.awau.moe/upload/pomf?key="$TOKEN" \
-H "User-Agent: $USER_AGENT")
echo "Uploaded! $OWO_OUTPUT"
# upload to owo
FILE=$(echo "$OWO_OUTPUT" | $JQ_PATH -r ".files[0].url")
URL="https://$VANITY/$FILE"
# copy
echo -n "$URL" | pbcopy
echo "Copied to clipboard: $URL"
# notify
/usr/bin/osascript -e "display notification \"$URL\" with title \"Uploaded!\""