An infinite loop prevention and shell prompt fix regarding #340

Hi there, please have a look at this trivial fix. I just added a check to prevent infinite loop while detecting shell and I just uncommented one pre-existing line of code that actually solves my problem and my shell is being detected with no problem. I don't even need to add custom pattern for our shell prompt. I hope this could close #340