bash: refactor and greatly improve prompt logic