#!/usr/bin/awk -f

BEGIN {
    FS  = "\t"
    OFS = ENVIRON["SB_BOOKMARK_PRETTY_OFS"]

    date_len  = ENVIRON["SB_BOOKMARK_PRETTY_DATE_LEN"]  + 0
    title_len = ENVIRON["SB_BOOKMARK_PRETTY_TITLE_LEN"] + 0
    ellipsis  = ENVIRON["SB_ELLIPSIS"]

    if (title_len < length(ellipsis))
        ellipsis = ""

    truncated_title_len = title_len - length(ellipsis)
    padding_for_titles  = sprintf("%-" title_len "s", "")
}

{
    title_padding_needed = title_len - length($3)

    print substr($1, 1, date_len),
          (title_padding_needed >= 0 ?
           $3 substr(padding_for_titles, 1, title_padding_needed) :
           substr($3, 1, truncated_title_len) ellipsis),
          $2
}
