Previously I have been using this handy script with oh-my-zsh to set the tab color whenever I ssh into a machine:

# iTerm2 window/tab color commands
#   http://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes
tab-color() {
    echo -ne "\033]6;1;bg;red;brightness;$1\a"
    echo -ne "\033]6;1;bg;green;brightness;$2\a"
    echo -ne "\033]6;1;bg;blue;brightness;$3\a"
tab-reset() {
    echo -ne "\033]6;1;bg;*;default\a"
    trap - INT EXIT

# Change the color of the tab when using SSH
# reset the color after the connection closes
color-ssh() {
    if [[ -n "$ITERM_SESSION_ID" ]]; then
        trap "tab-reset" INT EXIT
        if [[ "$*" =~ "production|ec2-.*compute-1" ]]; then
            tab-color 255 0 0
            tab-color 144 181 80 #0 255 0
    ssh $*
compdef _ssh color-ssh=ssh

alias ssh=color-ssh

However, today I have discovered that the autocomplete is now broken! My ssh no longer autocompletes if I run this script. How do I diagnose what is going on?

Edit: Disabling oh-my-zsh and sourcing the file leads to the error: command not found: compdef.

  • Starting with removing/disabling oh-my-zsh and see if it still happens is a good first step.
    – llua
    Jun 20, 2015 at 0:28
  • Thanks, but that wasn't the problem. I've edited the question.
    – yong
    Jun 20, 2015 at 0:44
  • This is (almost) totally unrelated to the point of your question (that's why I'm writing this as a comment and not an answer), but — I'm totally unfamiliar with zsh or oh-my-zsh.  Are they POSIX compliant?  Because, in any POSIX-compliant shell, if a function wraps a program, and invokes that program with all of the arguments that were passed to the function, it should use program-name "$@" instead of program-name $* Jun 20, 2015 at 0:51

2 Answers 2


Ok, I've found the solution: deleting all zcompdump files solved the problem:

rm ~/.zcompdump*

I ran the following and it fix the tab completion.

autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit
  • I had some frustrations then they were fixed by putting autoload -U compaudit && compinit at the bottom of my ~/.zshrc. (It was up higher in the file, before)
    – floer32
    Mar 9, 2021 at 1:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .