path coloring corner case better handled

Corner case: dirname is empty.
some refactor