If it were me, I'd go with a handgun. Handguns provide you with more versatility, in the sense that they can be used for home protection or carried for personal protection outside the home, and can be wielded more easily in tight spaces.
Pertinent to your question, Stack-On electronic, programmable combo, pistol safes can be had for the $40 range, whereas long guns require a considerably more-expensive and larger cabinet to be able to be secured and out of sight. In my opinion, that is a better option than simply pulling a small cable through the action or trying to hide it, then worrying about whether you can find it, or the key, if you ever need the gun, or whether they can find it, or the key, when you're not home.
Pistol safes can be lag-bolted directly to a stud, from inside the safe, and are very strong boxes. The model I have allows for a variable combination of one digit to six digits at my discretion, and will lockout for a time if the wrong combination is entered three times.
Other, slightly more-expensive models, are equipped with soft red nightlights for your use, and very loud alarms in addition to lockout functions for "unauthorized" fingers, as well as a different key tone the next time you use it, to let you know someone was trying.