This is the lua code I use in my StUF frames - it uses a shortened name, colored by class (Wild Wild West becomes W. W. West, for example), while at full HP.
At lower HP levels, it shows both the HP percentage and how much HP the target has lost (I often heal, so HP lost was important to me).
Code:
function(unit, cache, textframe)
local cc = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
if UnitExists(unit) then
cc = RAID_CLASS_COLORS[select(2, UnitClass(unit))]
end
local curhp, maxhp = UnitHealth(unit), UnitHealthMax(unit)
if curhp ~= maxhp then
local perchp, diffhp = 100 * curhp / maxhp, maxhp - curhp
return "|cff%02x%02x%02x%.0f|r%% | |cffc31d3a-%s|r",cc.r*255,cc.g*255,cc.b*255,perchp,diffhp
else
local name = UnitName("player")
if UnitExists(unit) then
name = UnitName(unit)
end
return "|cff%02x%02x%02x%s|r",cc.r*255,cc.g*255,cc.b*255,string.gsub(name, '%s?(.)%S+%s', '%1. ')
end
end
If you JUST want the name shortener, use this (from the link posted by Ketho above)
Code:
function(unit)
local name = UnitName(unit) or unit
name = name:gsub('(%S+) ',function(t) return t:sub(1,1)..'.' end)
return name
end
If you want class-coloring in it, just ask, and I'll whip up class coloring with it for ya.