A few things have helped me.
I noticed that I always feel my worst at night. I can have a great, happy day but sometimes, lying in bed trying to fall asleep, something in the back of my head tries to tell me I'm an absolute failure. It probably sounds silly, but when I was really struggling with depression, I made myself a promise that if I'm ever feeling like committing suicide, I'll put it off until the morning. There was something weirdly comforting for me about that. I don't have to wrestle with the decision; I can shrug and say, "Meh, maybe tomorrow."
You're apparently not supposed to tell suicidal people, "Think about how much it will hurt others!" because it just makes them feel even worse. But when I was considering it years ago, an image of my little brother popped into my head. He's (to use what seems like an inappropriate comparison in this situation) probably the only person in the world I'd give my life to defend. I realized he would be completely devastated if I died. And I realized that, if I was willing to die to protect him, I needed to be willing to live to protect him, even if it meant coping with the stuff that made me not want to.
Several years ago, I told my doctor that I felt sad a lot of the time. I was, unsurprisingly, diagnosed with depression, and found a medication that helped. I didn't know what to expect and had heard some scary things about anti-depressants, but it changed my life for the better. Don't rule it out as an option!