I’m usings home-manager on MacOS. I have zsh enabled and I want to add a custom function to .zprofile
The function is:
function awschrome {
# set to yes to create one-time use profiles in /tmp
# anything else will create them in $HOME/.aws/awschrome
TEMP_PROFILE="yes"
# set to yes to always start in a new window
NEW_WINDOW="no"
profile="$1"
if [[ -z "$profile" ]]; then
echo "Profile is a required argument" >&2
return 1
fi
# replace non word and not - with __
profile_dir_name=${profile//[^a-zA-Z0-9_-]/__}
user_data_dir="${HOME}/.aws/awschrome/${profile_dir_name}"
new_window_arg=''
if [[ "$TEMP_PROFILE" = "yes" ]]; then
user_data_dir=$(mktemp -d /tmp/awschrome_userdata.XXXXXXXX)
fi
if [[ "$NEW_WINDOW" = "yes" ]]; then
new_window_arg='--new-window'
fi
# run aws-vault
# --prompt osascript only works on OSX
url=$(aws-vault login $profile --stdout --prompt osascript)
#status=$?
#if [[ ${status} -ne 0 ]]; then
# bash will also capture stderr, so echo $url
# echo ${url}
# return ${status}
#fi
mkdir -p ${user_data_dir}
disk_cache_dir=$(mktemp -d /tmp/awschrome_cache.XXXXXXXX)
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--no-first-run \
--user-data-dir=${user_data_dir} \
--disk-cache-dir=${disk_cache_dir} \
${new_window_arg} \
${url} \
>/dev/null 2>&1 &
}
To do that I’m trying to use the profileExtra
option like
profileExtra = ''
function awsChrome{
...
}
When I do that I get errors like "syntax error, invalid token" when it hits the "^" or "syntax error, unexpected IF, expecting ;"
How can I include that function "as-is"?
'';