logoalt Hacker News

xorcist • today at 6:42 PM • 0 replies • view on HN

Not to rain on your fine snippet but you can use negative offsets to index from the end of the string:

  P="$PWD"
  [ ${#P} -gt $pwdmaxlen ] && P="$trunc_symbol${P: -$pwdmaxlen}"