#!/usr/bin/env bash
#
# ppdircolors - print LS_COLORS type, description (if available) in relevant color

IFS=:
for ls_color in ${LS_COLORS-}; do
  color="${ls_color#*=}"
  type="${ls_color%=*}"

  # add description for named types
  # desc="${descriptions[$type]}"

  # add descriptions for named types
  # shellcheck disable=SC2249
  case "${type}" in
    # bd) type+=" (block device)" ;;
    bd) type="${type} (block device)" ;;
    ca) type="${type} (file with capability)" ;;
    cd) type="${type} (character device)" ;;
    di) type="${type} (directory)" ;;
    do) type="${type} (door)" ;;
    ex) type="${type} (executable file)" ;;
    fi) type="${type} (regular file)" ;;
    ln) type="${type} (symbolic link)" ;;
    mh) type="${type} (multi-hardlink)" ;;
    mi) type="${type} (missing file)" ;;
    no) type="${type} (normal non-filename text)" ;;
    or) type="${type} (orphan symlink)" ;;
    ow) type="${type} (other-writable directory)" ;;
    pi) type="${type} (named pipe, AKA FIFO)" ;;
    rs) type="${type} (reset to no color)" ;;
    sg) type="${type} (set-group-ID)" ;;
    so) type="${type} (socket)" ;;
    st) type="${type} (sticky directory)" ;;
    su) type="${type} (set-user-ID)" ;;
    tw) type="${type} (sticky and other-writable directory)" ;;
  esac

  # separate each color with a newline
  if [ -n "${color_prev}" ] && [ "${color}" != "${color_prev}" ]; then
    echo
  fi

  printf "\e[%sm%s%s\e[m " "${color}" "${type}" "${desc:+ (${desc})}"

  # for next loop
  color_prev="${color}"
done
echo
