Just switched to using zsh (Oh-My-Zsh) and can't get autocompletion to work. Whenever I open a new terminal (using iTerm as well as VSCode terminal), the following output is printed to the terminal:
/usr/local/etc/bash_completion:59: command not found: shopt
/usr/local/etc/bash_completion:65: command not found: complete
/usr/local/etc/bash_completion:72: command not found: complete
/usr/local/etc/bash_completion:73: command not found: complete
/usr/local/etc/bash_completion:74: command not found: complete
/usr/local/etc/bash_completion:76: command not found: complete
/usr/local/etc/bash_completion:77: command not found: complete
/usr/local/etc/bash_completion:79: command not found: complete
/usr/local/etc/bash_completion:80: command not found: complete
/usr/local/etc/bash_completion:81: command not found: complete
/usr/local/etc/bash_completion:82: command not found: complete
/usr/local/etc/bash_completion:83: command not found: complete
/usr/local/etc/bash_completion:84: command not found: complete
/usr/local/etc/bash_completion:85: command not found: complete
/usr/local/etc/bash_completion:86: command not found: complete
/usr/local/etc/bash_completion:87: command not found: complete
/usr/local/etc/bash_completion:88: command not found: complete
/usr/local/etc/bash_completion:89: command not found: complete
/usr/local/etc/bash_completion:90: command not found: complete
/usr/local/etc/bash_completion:91: command not found: complete
/usr/local/etc/bash_completion:92: command not found: complete
/usr/local/etc/bash_completion:93: command not found: complete
/usr/local/etc/bash_completion:94: command not found: complete
/usr/local/etc/bash_completion:95: command not found: complete
/usr/local/etc/bash_completion:96: command not found: complete
/usr/local/etc/bash_completion:97: command not found: complete
/usr/local/etc/bash_completion:98: command not found: complete
/usr/local/etc/bash_completion:99: command not found: complete
/usr/local/etc/bash_completion:100: command not found: complete
/usr/local/etc/bash_completion:101: command not found: complete
/usr/local/etc/bash_completion:102: command not found: complete
/usr/local/etc/bash_completion:103: command not found: complete
/usr/local/etc/bash_completion:104: command not found: complete
/usr/local/etc/bash_completion:105: command not found: complete
/usr/local/etc/bash_completion:106: command not found: complete
/usr/local/etc/bash_completion:107: command not found: complete
/usr/local/etc/bash_completion:108: command not found: complete
/usr/local/etc/bash_completion:110: command not found: complete
/usr/local/etc/bash_completion:111: command not found: complete
/usr/local/etc/bash_completion:112: command not found: complete
/usr/local/etc/bash_completion:113: command not found: complete
/usr/local/etc/bash_completion:114: command not found: complete
/usr/local/etc/bash_completion:115: command not found: complete
/usr/local/etc/bash_completion:116: command not found: complete
/usr/local/etc/bash_completion:117: command not found: complete
/usr/local/etc/bash_completion:118: command not found: complete
/usr/local/etc/bash_completion:119: command not found: complete
/usr/local/etc/bash_completion:120: command not found: complete
/usr/local/etc/bash_completion:121: command not found: complete
/usr/local/etc/bash_completion:122: command not found: complete
/usr/local/etc/bash_completion:123: command not found: complete
/usr/local/etc/bash_completion:124: command not found: complete
/usr/local/etc/bash_completion:125: command not found: complete
/usr/local/etc/bash_completion:126: command not found: complete
/usr/local/etc/bash_completion:132: command not found: complete
/usr/local/etc/bash_completion:135: command not found: complete
/usr/local/etc/bash_completion:138: command not found: complete
/usr/local/etc/bash_completion:141: command not found: complete
/usr/local/etc/bash_completion:144: command not found: complete
/usr/local/etc/bash_completion:147: command not found: complete
/usr/local/etc/bash_completion:150: command not found: complete
/usr/local/etc/bash_completion:153: command not found: complete
/usr/local/etc/bash_completion:156: command not found: complete
/usr/local/etc/bash_completion:159: command not found: complete
/usr/local/etc/bash_completion:162: command not found: complete
/usr/local/etc/bash_completion:1192: command not found: shopt
/usr/local/etc/bash_completion:1367: command not found: complete
/usr/local/etc/bash_completion:1420: command not found: shopt
/usr/local/etc/bash_completion:1423: command not found: complete
/usr/local/etc/bash_completion:1523: command not found: complete
/usr/local/etc/bash_completion:1532: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
/usr/local/etc/bash_completion:1577: command not found: complete
(eval):1: command not found: complete
(eval):1: command not found: complete
/usr/local/etc/bash_completion.d/bash-builtins:20: command not found: complete
/usr/local/etc/bash_completion.d/bash-builtins:46: command not found: complete
/usr/local/etc/bash_completion.d/bash-builtins:69: command not found: complete
/usr/local/etc/bash_completion.d/bash-builtins:120: command not found: complete
/usr/local/etc/bash_completion.d/bind-utils:15: command not found: complete
/usr/local/etc/bash_completion.d/brctl:40: command not found: complete
/usr/local/etc/bash_completion.d/brew:870: command not found: complete
/usr/local/etc/bash_completion.d/bzip2:43: command not found: complete
/usr/local/etc/bash_completion.d/chsh:29: command not found: complete
/usr/local/etc/bash_completion.d/configure:36: command not found: complete
/usr/local/etc/bash_completion.d/coreutils:50: command not found: complete
/usr/local/etc/bash_completion.d/coreutils:94: command not found: complete
/usr/local/etc/bash_completion.d/coreutils:113: command not found: complete
/usr/local/etc/bash_completion.d/coreutils:141: command not found: complete
/usr/local/etc/bash_completion.d/cpan2dist:44: command not found: complete
/usr/local/etc/bash_completion.d/cpio:94: command not found: complete
/usr/local/etc/bash_completion.d/crontab:52: command not found: complete
/usr/local/etc/bash_completion.d/cups:13: command not found: complete
/usr/local/etc/bash_completion.d/dd:31: command not found: complete
/usr/local/etc/bash_completion.d/docker:69: command not found: shopt
/usr/local/etc/bash_completion.d/docker:70: command not found: shopt
/usr/local/etc/bash_completion.d/docker:5629: command not found: complete
/usr/local/etc/bash_completion.d/docker-compose:19: command not found: shopt
/usr/local/etc/bash_completion.d/docker-compose:20: command not found: shopt
/usr/local/etc/bash_completion.d/docker-compose:665: command not found: complete
/usr/local/etc/bash_completion.d/findutils:120: command not found: complete
/usr/local/etc/bash_completion.d/gcc:49: command not found: complete
/usr/local/etc/bash_completion.d/gzip:47: command not found: complete
/usr/local/etc/bash_completion.d/heimdal:124: command not found: complete
/usr/local/etc/bash_completion.d/iconv:38: command not found: complete
/usr/local/etc/bash_completion.d/info:50: command not found: complete
/usr/local/etc/bash_completion.d/jar:28: command not found: complete
/usr/local/etc/bash_completion.d/java:237: command not found: complete
/usr/local/etc/bash_completion.d/java:289: command not found: complete
/usr/local/etc/bash_completion.d/java:321: command not found: complete
/usr/local/etc/bash_completion.d/java:394: command not found: complete
/usr/local/etc/bash_completion.d/java:440: command not found: complete
/usr/local/etc/bash_completion.d/java:495: command not found: complete
/usr/local/etc/bash_completion.d/java:525: command not found: complete
/usr/local/etc/bash_completion.d/lsof:56: command not found: complete
/usr/local/etc/bash_completion.d/lzma:38: command not found: complete
/usr/local/etc/bash_completion.d/make:70: command not found: complete
/usr/local/etc/bash_completion.d/man:72: command not found: complete
/usr/local/etc/bash_completion.d/mount:132: command not found: complete
/usr/local/etc/bash_completion.d/mount:155: command not found: complete
/usr/local/etc/bash_completion.d/openldap:59: command not found: complete
/usr/local/etc/bash_completion.d/openldap:96: command not found: complete
/usr/local/etc/bash_completion.d/openldap:129: command not found: complete
/usr/local/etc/bash_completion.d/openldap:162: command not found: complete
/usr/local/etc/bash_completion.d/openldap:195: command not found: complete
/usr/local/etc/bash_completion.d/openldap:228: command not found: complete
/usr/local/etc/bash_completion.d/openldap:257: command not found: complete
/usr/local/etc/bash_completion.d/openssl:245: command not found: complete
/usr/local/etc/bash_completion.d/perl:82: command not found: complete
/usr/local/etc/bash_completion.d/perl:122: command not found: complete
/usr/local/etc/bash_completion.d/postfix:32: command not found: complete
/usr/local/etc/bash_completion.d/postfix:78: command not found: complete
/usr/local/etc/bash_completion.d/postfix:121: command not found: complete
/usr/local/etc/bash_completion.d/postfix:163: command not found: complete
/usr/local/etc/bash_completion.d/postfix:224: command not found: complete
/usr/local/etc/bash_completion.d/procps:22: command not found: complete
/usr/local/etc/bash_completion.d/procps:38: command not found: complete
/usr/local/etc/bash_completion.d/python:47: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:60: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:99: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:131: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:160: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:189: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:216: command not found: complete
/usr/local/etc/bash_completion.d/quota-tools:248: command not found: complete
/usr/local/etc/bash_completion.d/ri:87: command not found: complete
/usr/local/etc/bash_completion.d/rsync:84: command not found: complete
/usr/local/etc/bash_completion.d/screen:58: command not found: complete
/usr/local/etc/bash_completion.d/service:35: no matches found: /etc/init.d/*
/usr/local/etc/bash_completion.d/sh:33: command not found: complete
/usr/local/etc/bash_completion.d/shadow:171: command not found: complete
/usr/local/etc/bash_completion.d/shadow:314: command not found: complete
/usr/local/etc/bash_completion.d/shadow:326: command not found: complete
/usr/local/etc/bash_completion.d/shadow:415: command not found: complete
/usr/local/etc/bash_completion.d/sqlite3:31: command not found: complete
/usr/local/etc/bash_completion.d/ssh:194: command not found: shopt
/usr/local/etc/bash_completion.d/ssh:247: command not found: shopt
/usr/local/etc/bash_completion.d/ssh:393: command not found: complete
/usr/local/etc/bash_completion.d/ssh:419: command not found: complete
/usr/local/etc/bash_completion.d/sysctl:16: command not found: complete
/usr/local/etc/bash_completion.d/tar:63: command not found: complete
/usr/local/etc/bash_completion.d/tcpdump:29: command not found: complete
/usr/local/etc/bash_completion.d/util-linux:32: command not found: complete
/usr/local/etc/bash_completion.d/util-linux:52: command not found: complete
/usr/local/etc/bash_completion.d/util-linux:68: command not found: complete
/usr/local/etc/bash_completion.d/xmllint:47: command not found: complete
/usr/local/etc/bash_completion.d/xrandr:17: parse error near `)'
/usr/local/etc/bash_completion.d/xsltproc:48: command not found: complete
/usr/local/etc/bash_completion.d/xz:60: command not found: complete
/usr/local/etc/bash_completion.d/xz:94: command not found: complete
my /.zshrc
file contains the following:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
# Path to your oh-my-zsh installation.
export ZSH="/Users/p2915782/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir rbenv vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time virtualenv)
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
# Add a space in the first prompt
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%f"
local user_symbol="$"
if [[ $(print -P "%#") =~ "#" ]]; then
user_symbol = "#"
fi
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%{%B%F{black}%K{yellow}%} $user_symbol%{%b%f%k%F{yellow}%} %{%f%}"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
plugins=(virtualenv)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
When I try to autocomplete within terminal, I get the following error:
_get_comp_words_by_ref:16: bad substitution
I have tried multiple solutions like adding the following to the top of my ~/.zshrc
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
But I have not been able to find a solution yet.
Somewhere you're sourcing the whole of the bash_completion project - don't. Bash completions don't work in zsh and even if they did, they are worse than the native zsh ones. bashcompinit
is only useful with individual, carefully selected and tested functions. But is still better avoided.
It isn't clear where it is being sourced. The syntax highlighting plugin is unlikely. oh-my-zsh shouldn't be doing it either but I'd try disabling it first. Also check other startup files like .zshenv
, .zlogin
, .zprofile
and system files such as /etc/zshenv
.
Also, regarding the .zshrc you quoted: there's no need to pass +X
to autoload
, that's pointless. The second assignment to the plugins array is replacing the value from the first assignment. Did you want +=
instead? And if you want $ for a a normal user in the prompt and # for root, you can do that directly with %(!.#.$)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With