@@ -932,23 +932,57 @@ _cs_do_tab() {
932932
933933_cs_colorize () {
934934 local item=" $1 " prefix=" $2 "
935- local rest=" ${item: ${# prefix} } "
936935 local item_color=" "
937936 if [[ " $item " == * / ]]; then item_color=" 01;34"
938937 elif [[ -x " $item " && -f " $item " ]] 2> /dev/null; then item_color=" 01;32"
939938 elif [[ -L " $item " ]] 2> /dev/null; then item_color=" 01;36"
940939 elif [[ -d " $item " ]] 2> /dev/null; then item_color=" 01;38;5;69"
941940 fi
942- local reset=" \e[0m"
941+ local esc=$' \e '
942+ local reset=" ${esc} [0m"
943+
944+ if [[ -n " $prefix " && " $item " == * /* ]]; then
945+ local trailing_slash=" "
946+ local work=" $item "
947+ [[ " $work " == * / ]] && trailing_slash=" /" && work=" ${work%/ } "
948+ local base=" ${work%/* } /"
949+ local last=" ${work##*/ } "
950+
951+ local highlighted_last
952+ if [[ " $last " == " $prefix " * ]]; then
953+ local rest_last=" ${last: ${# prefix} } "
954+ if [[ -n " $item_color " ]]; then
955+ highlighted_last=" ${esc} [${item_color} ;04m${prefix}${reset}${esc} [${item_color} m${rest_last}${reset} "
956+ else
957+ highlighted_last=" ${esc} [01;35;04m${prefix}${reset}${rest_last} "
958+ fi
959+ else
960+ if [[ -n " $item_color " ]]; then
961+ highlighted_last=" ${esc} [${item_color} m${last}${reset} "
962+ else
963+ highlighted_last=" ${last} "
964+ fi
965+ fi
966+
967+ if [[ -n " $item_color " ]]; then
968+ printf ' %s%s%s' " ${esc} [${item_color} m${base}${reset} " " $highlighted_last " " $trailing_slash "
969+ else
970+ printf ' %s%s%s' " $base " " $highlighted_last " " $trailing_slash "
971+ fi
972+ return
973+ fi
974+
975+ # Item sem '/' — comportamento original
976+ local rest=" ${item: ${# prefix} } "
943977 if [[ -n " $item_color " ]]; then
944978 if [[ -n " $prefix " ]]; then
945- printf " \e [${item_color} ;04m%s ${ reset}\e[ ${item_color} m%s ${reset} " " $prefix " " $ rest"
979+ printf ' %s%s ' " ${esc} [${item_color} ;04m${prefix}${ reset}${esc} [ ${item_color} m " " ${ rest}${reset} "
946980 else
947- printf " \e [${item_color} m%s ${reset} " " $item "
981+ printf ' %s ' " ${esc} [${item_color} m${item}${reset} "
948982 fi
949983 else
950984 if [[ -n " $prefix " ]]; then
951- printf " \e [01;04m%s ${reset} %s " " $prefix " " $rest "
985+ printf ' %s%s ' " ${esc} [01;04m${prefix}${reset} " " $rest "
952986 else
953987 printf ' %s' " $item "
954988 fi
0 commit comments