Get word under the caret in Terminal.app

I can get the current prompt line with something like: tell app "Terminal" to tell selected tab of window 1 to do shell script "echo '" & history & "' | sed '/^$/d' | tail -n1 | cut -d$ -f2-"