FYI, there is a handgun orbiting the earth right now. It's in the survival kit in the Soyuz capsule docked to the International Space Station. Purpose is defense of the capsule from wild animals if they come down off course. (This has happened. One cosmonaut in the '60s spent a night in his capsule because he was surrounded by wolves.)
At least two of the early "Salyut" space stations were actually military installations using the civilian program as cover. Word is that a couple of these were armed with a 20mm recoilless automatic cannon (using some sort of rearward gas venting to negate recoil). I think one was test fired by remote control after the crew left.
The Russian 'Polyus' military space station that was destroyed by a booster malfunction ca. 1990 had lots of wild weaponry on board (it was a test bed for various anti-ICBM technology). Supposedly had an automatic cannon, an experimental particle beam weapon, and prototype interceptor missiles. The guidance platform on the Energia booster upper stage failed and the insertion-to-orbit burn was made in the wrong direction, causing the unmanned station to reenter. Oops.
Mark Wade's Encyclopedia Astronautica has photos and diagrams of some of these.
Regarding shooting yourself down--if I recall correctly, shooting a gun in orbit would put the bullet in an elliptical orbit that would intersect your orbit only at the point at which you fired the weapon, i.e. if you fired upward then the perigee of the bullet's new orbit would intersect yours at that point. To put it in a non-intersecting orbit you would have to accelerate the bullet again some time after it was fired, or just do like the Salyut/Almaz plan was and maneuver your spacecraft immediately after firing your gun so you don't hit the projectiles later.
IIRC, one of Robert Heinlein's early stories involved a gun battle with Nazis on the moon, which brings up an interesting point. IF I remember correctly from Apollo mission writeups, the velocity necessary to orbit the moon is around 2000 mph, which is well within the range of high-velocity centerfire rifles. So theoretically, if you shoot a .223 or .220 Swift on the moon parallel to the surface, the bullet will orbit a few times if you do it right (i.e., if the 'perigee' doesn't intersect the surface first), until the orbit gets perturbed enough to hit a mountain or touch the surface. Alternatively, you could make a higher angle shot and drop a round halfway around the moon.
bE