-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome-session.sh
executable file
·60 lines (51 loc) · 1.27 KB
/
chrome-session.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
#!/bin/bash
#
# Launches chrome as an nth independent session
#
# follow symlinks
script_dir="$(cd "$(dirname "$([[ -h "$0" ]] && readlink "$0" || echo "$0")")" && pwd)"
usage() {
echo "Usage: $(basename "$0") [[-s] session-number]"
echo -e "\nOptions:"
echo -e "\t-s"
echo -e "\t\tnth session to launch"
exit 1
}
# defaults
session_num=0
set_session() {
if [[ ! "$1" =~ ^[0-9]+$ ]]; then
echo -e "Invalid session number: $1\n"
usage
fi
session_num="$1"
}
while getopts "s:" opt; do
case "$opt" in
s)
set_session "$OPTARG"
;;
*)
usage
;;
esac
done
OPTIND=1
# support shorthand session number selection and prevent unintentional misuse
if [[ ${#1} -gt 0 ]]; then
set_session "$1"
fi
# detect OS to support overrides
shopt -s nocasematch
case "$(uname -a)" in
*darwin*) launch_command="open -a 'google chrome' -n --args";;
*) launch_command='chrome';;
esac
shopt -u nocasematch
# user data dir allows independent session simulation, when 0, will use the system default
if [[ "$session_num" -gt 0 ]]; then
data_dir="$script_dir/tmp/$session_num"
mkdir -p "$data_dir"
launch_command="$launch_command --user-data-dir=\"$data_dir\""
fi
eval $launch_command