-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser
executable file
·135 lines (126 loc) · 3.17 KB
/
browser
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
#!/bin/sh
# General script to start a browser. Possible browsers:
# graphical: firefox qutebrowser dwb luakit jumanji surf uzbl
# text: elinks w3m links lynx
type=graphical
mode=normal
branch=normal
pipe=false
usage () {
local prog=${0##*/}
echo "Usage: $prog [-dgptx] [url]"
echo " cat file.html | $prog -s [options]"
echo " $prog -h"
}
help () {
usage
echo
printf ' %s\t%s\n' \
-d 'use development code of the browser' \
-g 'open a graphical browser' \
-h 'show this help' \
-p 'start in private browsing mode (implies -g)' \
-s 'expect document on stdin (no url allowed)' \
-t 'open a text browser' \
-x 'activate debug output' \
}
qutebrowser () {
qutebrowser_$mode "$@"
}
qutebrowser_dev () {
#export QT_QPA_PLATFORM=wayland-egl QT_WAYLAND_DISABLE_WINDOWDECORATION=1
export PYTHONPATH=~/vcs/qutebrowser
python -m qutebrowser "$@"
}
qutebrowser_stable () {
command qutebrowser "$@"
}
qutebrowser_normal () {
qutebrowser_stable "$@"
}
qutebrowser_private () {
local tempdir=$(mktemp -d)
cp -r ~/.config/qutebrowser "$tempdir/config"
mkdir "$tempdir/data"
cp -r ~/.local/share/qutebrowser/userscripts "$tempdir/data/userscripts"
#trap 'rm -rf "$tempdir"' EXIT SIGTERM SIGKILL
qutebrowser_$branch \
--basedir "$tempdir" \
--set auto_save.session false \
--set content.javascript.enabled false \
:adblock-update \
"$@"
#--set content.headers.user_agent 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36' \
rm -rf "$tempdir"
}
firefox_profiles () {
local ini=$HOME/.mozilla/firefox/profiles.ini
grep '^Name=' "$ini" | cut -f 2 -d =
}
firefox_mac () {
local profile
for profile in $(firefox_profiles); do
if [ "$profile" = "$1" ]; then
# TODO
exec open -na Firefox --args -P "$profile" -no-remote
fi
done
echo "$1 is not a valid profile. Try one of $(firefox_profiles)."
exit 2
}
firefox () {
export VIMPERATOR_RUNTIME=~/.config/vimperator
export VIMPERATOR_INIT="source $VIMPERATOR_RUNTIME/vimperatorrc"
exec firefox "$@"
}
firefox_new () {
local user=${1:-$USER}
shift
firefox -new-instance -P "$user" "$@"
}
firefox_private () {
exec firefox --new-instance --private-window "$@"
}
text () {
local text_browser=elinks
if [ -t 1 ] || [ -t 2 ]; then
exec "$text_browser" "$@"
else
exec term -e "$text_browser" "$@"
fi
}
graphical () {
qutebrowser "$@"
}
while getopts hdgpstx opt; do
case $opt in
d) branch=dev;;
g) type=graphical;;
h) help; exit;;
p) mode=private;;
s) pipe=true;;
t) type=text;;
x) set -x;;
*) usage >&2; exit 2;
esac
done
shift $((OPTIND-1))
if [ $# -eq 1 ] && [ "$1" = - ]; then
shift
pipe=true
fi
if $pipe; then
# save stdin to a file
file=$(mktemp -t tmp-$$-XXXXXX) || exit 3
trap 'trap - HUP INT TERM; rm -f "$file" "$file.html"' HUP INT TERM
cat > "$file" || exit 4
case $(file --brief --mime-type "$file") in
text/html)
mv "$file" "$file.html"
file=$file.html
;;
esac
$type "$file"
else
$type "$@"
fi