-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintercept-browser.sh
executable file
·42 lines (34 loc) · 993 Bytes
/
intercept-browser.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
#!/usr/bin/env bash
url="$1"
urlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for ((pos = 0; pos < strlen; pos++)); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9]) o="${c}" ;;
*) printf -v o '%%%02x' "'$c" ;;
esac
encoded+="${o}"
done
echo "${encoded}"
}
handle_google_login() {
account="$(gcloud auth list --filter='active' --format 'value(account)')"
echo "ext+container:name=${account}&url=$(urlencode "$1&autoAccountSelect=${account}")"
}
open_in_container() {
account="$(gcloud auth list --filter='active' --format 'value(account)')"
echo "ext+container:name=${account}&url=$(urlencode "$1")"
}
if [[ $url =~ https://accounts.google.com/o/oauth2/auth ]]; then
url=$(handle_google_login "$url")
elif [[ $url =~ (fasit|monitoring).nais.io ]]; then
url=$(handle_google_login "$url")
elif [[ $url =~ https://(www.)?youtube.com ]] || [[ $url =~ https://(www.)?youtu.be ]]; then
mpv "$url"
exit 0
fi
firefox "$url"