That last bit doesn't take long, only a few thousand years before the gas expands so much it becomes too thin to get lit up and be seen. What's even shorter is the time between the star shedding those outer layers into space, and when they get lit up in the first place. That phase is called the proto-planetary nebula, and is so short that only a few of these objects are known. One of them is IRAS 13208-6020, seen here in a Hubble image. The gas there isn't glowing on its own just yet; it's simply reflecting the light from its star. Very soon, perhaps in the next millennium or two, the star you can see in the center will shed those last bits of gas on top of it, exposing it fully to space, and the weird lobes of material will glow far more brightly, becoming a planetary nebula proper.
Nebulae like this come in all sorts of shapes, from almost perfectly round to extremely elongated like this one. We suspect that this may be due to planets orbiting the star getting swallowed up as the star expands; the orbiting planets whip it up like an eggbeater and focus the gas into these fantastic shapes. So oddly, planets do have something to do with planetary nebulae. It's funny; sometimes art imitates nature, which then turns righ around and imitates art.
Image credit: ESA/Hubble & NASA