Sunday, August 21, 2016

Launch Chrome by Profile Name (Updated)

Now for my once a decade update... Chrome eliminated white space from the JSON format used to store profile preferences. This broke the simple file parsing of the previous script. This update switches to the jq command-line JSON parser to fix the parsing. Enjoy:
#!/usr/bin/env bash
if [[ $# -eq 0 ]]; then
exec google-chrome &
exit 0
elif [[ $1 == "incognito" ]]; then
exec google-chrome --incognito &
exit 0
else
for preffile in ~/.config/google-chrome/{Default*,Profile*}/Preferences; do
[[ -e "$preffile" ]] || continue;
profname=$(jq ".profile.name" "$preffile")
echo "Found profile $profname in $preffile."
if [[ "$profname" == "\"$1\"" ]]; then
shift
profdir=$(echo "$preffile" | sed -e 's|^.*google-chrome/\([^/]*\)/Preferences$|\1|')
echo "Going to launch profile $profname with profile directory $profdir."
exec google-chrome --profile-directory="$profdir" "$@" &
exit 0
fi
done
echo "Profile with name $1 not found!"
exit 1
fi
view raw gchrome hosted with ❤ by GitHub
Send peer bonus, please :-)