I've found that behavior that isn't quite a ritual, but unique to that activity can be highly motivating and beneficial to focus as well. Whenever I want to get deeply focused on code writing, I'll start speaking to myself under my breath. A bit like the intention behind vocalizing your thoughts during a coding interview, it's been very helpful for keeping my mind on track.