This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ $# -eq 0 ]; then | |
exec google-chrome & | |
exit 0 | |
else | |
for preffile in ~/.config/google-chrome/{Default,Profile*}/Preferences; do | |
# The profile name appears to always be the last "name:" in the json | |
# of the Preferences file. Yes, fragile, but appears to work for now. | |
profname=$(grep \"name\" "$preffile" | tail -1 | sed -e 's/.*"\([^"]*\)",\?$/\1/') | |
if [ "$1" == "$profname" ]; then | |
profdir=$(echo "$preffile" | sed -e 's|^.*google-chrome/\([^/]*\)/Preferences$|\1|') | |
echo "Going to launch with profile directory: $profdir" | |
exec google-chrome --profile-directory="$profdir" & | |
exit 0 | |
fi | |
done | |
# didn't find that profile name | |
echo "Profile named $1 not found!" | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _gchrome_profile() { | |
local IFS=$'\n' | |
local param=${COMP_WORDS[COMP_CWORD]} | |
local profiles="" | |
local preffile | |
for preffile in ~/.config/google-chrome/{Default,Profile*}/Preferences; do | |
# The profile name appears to always be the last "name:" in the json | |
# of the Preferences file. Yes, fragile, but appears to work for now. | |
local name=$(grep \"name\" "$preffile" | tail -1 | sed -e 's/.*"\([^"]*\)",\?$/\1/') | |
profiles="$profiles | |
$name" | |
done | |
COMPREPLY=( $(compgen -W "$profiles" "$param") ) | |
} | |
complete -F _gchrome_profile gchrome |