You can see what each tput commands are doing by running infocmp. Most TERM implement ANSI-compatible escape codes, but may prefer other escape codes for the same effect (e.g. try comparing `infocmp -1 ansi` and `infocmp -1 xterm` and `infocmp -1 screen`). You can see the entire list of these commands in terminfo(5) (`man 5 terminfo`) in Predefined Capabilities section.
If your terminal ($TERM) is not known to the operating system, you can also import the terminfo definition from another OS in a directory and point the TERMINFO environment variable to it (useful if the legacy OS you connect to via SSH doesn't have full support for your fancy terminal emulator).
Save and Restore cursor doesn't always work because I don't necessarily need the vertical position restored, for example:
ls_color () {
tput sc;
/bin/ls --color=auto "$@";
push_cursor_position;
tput rc;
pop_cursor_position
}tput is a neat command that I wish got used more! I also use `tput cnorm` to ensure the cursor is visible.
It’s more efficient to echo CSI 0m, in shell than to run another process to do the same. Every mainstream terminal supports it.