The nails on my right hand used to be roughly an inch or a little longer for the guitar. I eventually clipped them off so I could pick up the bass again.
I kept myself from peeling them by just developing another habit that was just as satisfying, like peeling the fingernails on my left hand instead (Which was also a plus cause it made fretting easier) and peeling my toenails (I obviously used hand sanitizer afterwards :P). I also fiddle my hair a lot and, what I've found to be one of the best replacements, I carry around a paper clip everywhere and bend it into different shapes.
As for keeping them in tact, all you can really do is work on making yourself constantly aware of them.