If the cable is old/dirty enough for the barrel to snap off then the housing lining is old too, causing undesirable performance
Order new cable it's worth it, New housing, new fresh cable, smooth long lasting performance
Also buy some Cable Lube / Silicone with Teflon it's the best, squirt some in your brake and clutch cables too
Point the little red tube directly into the cable housing and squirt Wrap a rag or plastic around it to minimize over spray waist
(cable lube) Silicone with Teflon is also the best lubricant for locks too
Here, I sprayed some in my M/C saddle bag locks
I had a shifter cable snap awhile back and I just took a plain wire connector and crimped it REALY HARD and then put some shrink tube over it, no solder, and it never broke.