If you want to avoid thinking the "What was I thinking?" thoughts, the first step is to approach God for wisdom, so that in hindsight you'll love whatever it was you were thinking.