I just had this problem, luckily at home, but not after I pulled half the gear area apart to only find it was the lever on the gearbox instead....
I followed the original approach, but I used an M6 bolt instead, and spacers made from the shell/outside of a concrete anchor bolt, also a M6. The outside shell acts as a spacer that fits into the end of the gearshift cable (because it is 8mm), but you probably have to drill it out the end of the cable with a 6mm drill for it to fit. You need to cut off about 2mm to use as a spacer in the lever itself and about 12mm to push into the cable to act as a pivot.
I used a nut to hold the bolt to the lever, and then a washer, then the spacer in the head of the gear cable, another washer, and then a nyloc to hold it all together. I think its a better approach as it uses the metal sleeve from the anchor bolt as a pivot for the cable, and when you tighten up the nyloc, it binds against the sleeve/spacer instead of the gear cable itself. This means that the cable can pivot easily but can't fall off either.