How can I make sure that the title of a Terminal tab/window is identical to the command I typed

macOS Catalina (10.15) now uses Zsh, which makes this really easy.

Show the currently running / last run command by disabling auto_title and adding a preexec hook:

# File: ~/.zshrc

DISABLE_AUTO_TITLE="true"

preexec() {
    printf "\e]1;${1}\a"
}