Skip to content

Instantly share code, notes, and snippets.

@dburger
Last active December 18, 2015 09:08
Show Gist options
  • Save dburger/5758862 to your computer and use it in GitHub Desktop.
Save dburger/5758862 to your computer and use it in GitHub Desktop.
bash shell function to add chrome profile name completion to a "gchrome" command.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment