forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-io.sh
executable file
·37 lines (31 loc) · 849 Bytes
/
git-io.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
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Shorten URL from GitHub
# @raycast.mode silent
# @raycast.packageName Browsing
# Optional parameters:
# @raycast.icon images/git-io.png
# Documentation:
# @raycast.author Astrit
# @raycast.authorURL https://github.com/astrit
# @raycast.description Shorten any github.com URL
regex='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]?(github)\.(com|io)'
getLink=$(pbpaste)
if [[ $getLink =~ $regex ]]
then
result=$(curl -i https://git.io -F "url=$getLink" | grep Location)
location="Location: "
resultCleanup=${result//$location/}
if [[ $result != "Error" ]]
then
echo $resultCleanup | pbcopy
echo "Copied URL: $resultCleanup"
else
echo "URL cannot be shortened"
exit 1
fi
else
echo "String in clipboard is not a valid URL"
exit 1
fi