Artificial intelligent assistant

Outputting a string in the bottom right corner of the terminal How do I output a string in the bottom right corner of the terminal?

string=whatever
stty size | {
read y x
tput sc # save cursor position
tput cup "$((y - 1))" "$((x - ${#string}))" # position cursor
printf %s "$string"
tput rc # restore cursor.
}


That assumes all characters in `$string` are one _cell_ wide (and that `$string` doesn't contain control characters (like newline, tab...)).

If your _string_ may contain zero-width (like combining characters) or double-width ones, you could use ksh93's `printf`'s `%Ls` format specifier that formats based or character width:


string='́'
# aka string=$'\uFF57\uFF48\uFF41\uFF54\uFF45\u0301\uFF56\uFF45\uFF52'
stty size | {
read y x
tput sc # save cursor position
tput cup "$((y - 1))" 0 # position cursor
printf "%${x}Ls" "$string"
tput rc # restore cursor.
}


That would erase the leading part of the last line though.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy c8890449d9236690fcccfd6bf16a51ad