Rather than literally embed that contents the $1 into the json string which you could do with:
lb() {
composer config "repositories.$1" '
{
"type": "path",
"url": "/b/'"$1"'-bundle"
}'
}
You could also get jq to generate the json using the proper encoding with:
lb() {
composer config "repositories.$1" "$(
URL="/b/$1-bundle" jq -cn '
{
"type": "path",
"url": $ENV.URL
}')"
}
That way, it works correctly even if $1 contains characters that are special in the JSON syntax (not that it should happen for URLs).
Beware that jq transforms bytes that can't be part of UTF-8 characters to � (U+FFFD the replacement character). JSON strings can't hold arbitrary sequence of bytes, only UTF-8 encoded characters.
In a URL anyway, those bytes should be encoded as %XX. jq does have a @uri operator to URI-encode a string so you could do:
lb() {
composer config "repositories.$1" "$(
URL="/b/$1-bundle" jq -cn '
{
"type": "path",
"url": ($ENV.URL | @uri)
}')"
}
However, unfortunately, that would apply after the translation to �, so wouldn't let you properly URI-encode any byte sequence (like the ones that can't be decoded as UTF-8).
You'd need the URI encoding to be done before jq. If using ksh93 instead of bash, that could be done with its builtin printf for instance:
function lb {
typeset -x URL=${
LC_ALL=C printf '%(url)q' "/b/$1-bundle"
}
composer config "repositories.$1" "${
jq -cn '
{
"type": "path",
"url": $ENV.URL
}'
}"
}
Or you could use proper programming languages like perl or ruby that come with proper URI / JSON manipulation modules.
Beware ksh93's printf, like jq's @uri encode / as %2F which may or may not be desirable.