bash_completion: Move common code into function