Append to PATH-like variable without creating leading colon if unset
You are on the right track with the ${:+}
expansion operator, you just need to modify it slightly:
V=${V:+${V}:}new_V
The first braces expand to $V
and the colon iff V
is set already otherwise to nothing - which is exactly what you need (and probably also one of the reasons for the existence of the operator).
Thus in your case:
export "PKG_CONFIG_PATH=${PKG_CONFIG_PATH:+${PKG_CONFIG_PATH}:}$(pyenv prefix)/lib/pkgconfig"