I have installed zsh and oh my zsh on Ubuntu 18.04. I would like to use autocompletion for kubectl. Therefore I have added source <(kubectl completion zsh) to my ~/.zshrc file.
On execution of this script zsh gets the following error:
complete:13: command not found: compdef
The kubectl documentation states that when one gets the error above, you should put the following on top of the .zshrc file:
autoload -Uz compinit
compinit
After doing this and restarting the terminal, I get the same error.
In a git-issue I found the following helped people with a common issue:
#This will perform chmod g-w for each file returned by compaudit to remove write access for group
compaudit | xargs -I % chmod g-w "%"
#This will perform chown to current user (Windows and Linux) for each file returned by compaudit
compaudit | xargs -I % chown $USER "%"
#Remove all dump files (which normally speed up initialization)
rm ~/.zcompdump*
#Regenerate completions file
compinit
zsh logs the following while running the script:
kubescript:12457: command not found: _bash_comp
Unfortunately this did not solve my problem. What else can I do to fix my issue? Or even still: what can I do to find out what is causing it?
I fixed the error by using the following code in .zshrc:
# K8s auto-complete
autoload -U +X compinit && compinit
source <(kubectl completion zsh)
You may also do it using oh-my-zsh plugin if you use oh-my-zsh.
I had the same issue and it was solved updating nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
For my OSX 10.15.7 I did something similar
vi ~/.zshrc
alias k=kubectl
autoload -U +X compinit && compinit
[[ /usr/local/bin/kubectl ]] && source <(kubectl completion zsh)
Works like a charm!
I encountered this after installing the Angular CLI. Turns that Angular adds something into your .zshrc file.
If you recently installed Angular CLI, open ~/.zshrc and remove the lines added by Angular CLI.
After trying lot of options and going through diff treads. It worked for me after running below command
autoload -Uz compinstall && compinstall
This configures the ~/.zshrc and initialize the compinit by adding these 2 below lines:
autoload -Uz compinit
compinit
and then run below sudo commands which mentioned in link
$ sudo chmod -R 755 /usr/local/share/zsh
$ sudo chown -R root:staff /usr/local/share/zsh
$ compaudit | xargs chmod g-w
at last restart the terminal.
Hope this helps for someone.
In my case the issue was fixed after re-installing oh-my-zsh:
Deleted my old version rm -rf ~/.oh-my-zsh
Installed from https://github.com/ohmyzsh/ohmyzsh
I really tried every answer here, but nothing worked.
So, I tried this tutorial paying attention to the last observation:
"Note: Make sure you add this snippet before any call to compdef else you will still see the error"
I had a complete call from Terraform installation in my ~/.zshrc and ~/.bash_profile files.
https://thysmichels.com/2020/07/16/mac-solved-command-not-found-compdef/
For me I had this line:
source ~/.oh-my-zsh/plugins/git/git.plugin.zsh
In my ~/.zshrc file. Which was trying to source the plugin before it is loaded by plugins=(git)
Removing that line fixed it for me.
If you have added the plugins and everything works well, One of the reasons is you may be trying to use the plugin before it is loaded. As in my case.
This issue is (also) faced after installing Angular CLI (Angular Version 14.x) and accepting addition of autocompletion for the cli commands. Snippet from .zshrc:
# Load Angular CLI autocompletion.
source <(ng completion script)
Commenting out the source line resolved the issue for me (macOS 12.6 (21G115)).
# Load Angular CLI autocompletion.
# source <(ng completion script)
Still need to work out the root cause.
Related
I have a basic script that installs and configures Oh My Zsh taking advantage of the omz command.
Here is a snippet:
/bin/zsh -i -c "\
omz theme set pygmalion &&\
omz plugin enable nvm &&\
omz plugin enable zsh-autosuggestions"
Unfortunately only the first command runs.
Even if I try to run
omz theme set pygmalion && omz plugin enable nvm && omz plugin enable zsh-autosuggestions
directly in my shell only the first theme command will be executed.
How to run all of those commands at once, inside of a script?
The omz function runs exec zsh after changing the configuration in order to reload zsh with the changes. That completely replaces the shell instance, which means anything else the shell was planning on doing (e.g. the commands after && or ;) will be discarded.
You can see this in a short example:
> print BEFORE; exec zsh; print AFTER
BEFORE
Some possible work-arounds.
Option 1 - Call zsh multiple times.
zsh -i -c 'omz theme set pygmalion'
zsh -i -c 'omz plugin enable nvm'
zsh -i -c 'omz plugin enable zsh-autosuggestions'
The omz function will relaunch the shell within each call, but since there is only one command in each instance, nothing will be lost when the exec zsh is performed.
Option 2 - Non-interactive zsh.
In the omz function, the exec zsh is only run in an interactive shell, so launching zsh without the -i option should allow the subsequent commands to execute.
Unfortunately, in the default oh-my-zsh setup, the omz function is set from .zshrc and is therefore only available in interactive shells. This means a bit more code is needed to load the function:
zsh -c "
. $ZSH/lib/cli.zsh
omz theme set pygmalion
omz plugin enable nvm
omz plugin enable zsh-autosuggestions"
If the ZSH variable isn't set when you make this call, you'll need to figure out its value (it's often ~/.oh-my-zsh/).
Option 3 - Set .zshrc directly.
It appears that the omz calls are just changing some lines in the .zshrc file, so you could make those changes from the script. A simple form might look something like this:
print 'ZSH_THEME="pygmalion"
plugins+=(nvm zsh-autosuggestions)' >> ~/.zshrc
A more complex version could check to ensure that this isn't adding duplicate lines to the file (which is one of the things the omz script is doing).
All of this seems kinda cumbersome. You may want to ask the OMZ maintainers if there is another option for updating configurations that avoids this issue.
When I change my branch inside my zsh sadly it is not reflecting the current branch if I use an alias, but works if I use git checkout <branch>.
I use oh-my-zsh and my custom theme for oh-my-zsh hosted on github.
My current zsh version is:
❯ zsh --version
zsh 5.7.1 (x86_64-apple-darwin18.2.0)
My aliases look like the following:
❯ alias | grep gc
gc='git checkout'
gco='git commit'
My git version is:
❯ git --version
git version 2.21.0
Any ideas what could cause this and how to fix it?
The problem is caused by vcs_info as it is not called if the last command is not containing git or svn, as checked in steeef_preexec.
The solution could be to just check vcs_info every-time. This is slow but solve the issue detecting even alias changes.
I've been using oh-my-zsh for a while and it's working great. I'd like to use the command-line fuzzy finder plugin so I enabled it in .zshrc:
plugins=(fzf)
However if "fzf" is not installed I get a warning when opening my terminal window:
[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
Please add export FZF_BASE=/path/to/fzf/install/dir to your .zshrc
Is there a way to hide that warning message? When I install fzf with "sudo dnf install fzf" the warning dissapears, but maybe I want to clone my dotfiles on a different computer where it is not available and it's not that important to be there.
you should first install fzf, in Mac and i use the following command to install brew install fzf
You need to have fzf installed to use this plugin; otherwise remove it. It won't do anything without first installing fzf. Sudo apt install fzf
You can put the plugins= line inside an if statement that checks for the presence of fzf in your path. For example:
if [[ -n $(command -v fzf) ]] ; then
echo "fzf found, loading oh-my-zsh fzf plugin"
plugins=(vi-mode fzf)
else
echo "no fzf was found in the path"
plugins=(vi-mode)
fi
command -v is similar to which, but is superior for this context as explained in this answer.
The -n makes the [[ ]] evaluate as true whenever the $() produces a non-empty output.
For me, it was also very important that brew itself was in Path of ~/.zshenv like so:
export PATH=/opt/homebrew/bin:$PATH
Installed FZF with brew on an M1 Mac.
Otherwise, the error occurs:
[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
Please add `export FZF_BASE=/path/to/fzf/install/dir` to your .zshrc
When you install fzf by using brew, it needs to be set brew env.
You can solve to set PATH for fzf before the line of plugins=(fzf) in .zshrc file.
But, I recommand creating "$HOME/.zprofile" as following.
For m1 Mac.
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
For, intel Mac
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/usr/local/bin/brew shellenv)"
I have been using oh-my-zsh for a while now and the docker plugin as recently stopped working for me for some reason.
I checked my ~/.zshrc file and the plugin is included
plugins=(git colored-man colorize github jira vagrant virtualenv pip python brew osx zsh-syntax-highlighting docker)
I checked the ~/.oh-my-zsh/plugins/docker directory and there is a _docker file in there. Yet when I type docker and press Tab, I get none of the autocomplete shortcuts that I used to get.
I can confirm that my git plugin works just fine but not the docker plugin. Tried doing exec zsh and source ~/.zshrc and restarted my terminal but no luck.
Am I missing something?
You might want to try and remove any .zcompdump-(...) files you may have on your user's home directory - using something like rm ~/.zcompdump* on a terminal, or some file browser - and then reload the .zschrc file with the command source ~/.zshrc or restart the terminal - whichever works best for you. See this
Then see if it works.
It seems oh-my-zsh is not loading plugins/docker/_docker file. You must add it to ~/.zshrc in an another way.
Add these lines to your ~/.zshrc file:
fpath+=($ZSH/plugins/docker)
autoload -U compinit && compinit
For me it was simply the case that I needed to launch Docker for the first time from spotlight on my Mac in order for Docker for Desktop to get the access it needed. Then the docker version command worked just fine.
Follow these steps if you are using oh-my-zsh and autocomplete is not working:
Make the following three links:
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion /usr/local/share/zsh/site-functions/_docker
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.zsh-completion /usr/local/share/zsh/site-functions/_docker-machine
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.zsh-completion /usr/local/share/zsh/site-functions/_docker-compose
Either add autoload -Uz compinit; compinit to .zshrc or run in your shell:
echo "autoload -Uz compinit; compinit" >> .zshrc
In my case: Windows 10 + WSL2 + Hyper
I was having this error because I stopped Docker on Windows... Starting it again makes the error disappear in Hyper (thus, also in ZSH).
No .zshrc changes or additional commands to add inside.
#youhans's solution worked for me permanently. You might have permission issue to make needed adjustment on "zshrc". I have changed the permission to "read and write" and added the code snippet from #youhans's response to the end of "zshrc" file. Now completion system always works.
Before I had to type below snippet in command line whenever open a new terminal.
autoload -Uz compinit && compinit
In my case it occurred because of an alias. I had defined alias docker=docker.exe.
Removing that did it work again.
System & Environment
O.S.: Windows 10 Home, x64
Shell: Zsh (on Gitbash)
I think you may be missing ,'s in between each plugin.
plugins=(git, colored-man, colorize, github, jira, vagrant, virtualenv, pip, python, brew, osx, zsh-syntax-highlighting, docker)
Alternatively you can place each plugin on a separate line:
plugins=(
git
colored-man
colorize
github
jira
vagrant
virtualenv
pip
python
brew
osx
zsh-syntax-highlighting
docker
)
autojump on ArchLinux for some reason is not working in zsh.
Although If I switch to bash it works fine.
$ sudo pacman -S autojump
autojump: does not work on zsh
$ source /usr/etc/profile.d/autojump.sh
$ j
zsh: command not found: j
$ source /usr/etc/profile.d/autojump.bash
$ j
zsh: command not found: j
autojump: works on bash
$ bash
(bash) $ source /usr/etc/profile.d/autojump.bash
(bash) $ j
autojump: ...
My environment:
$ echo $SHELL
/bin/zsh
$ zsh --version
zsh 5.0.2 (x86_64-unknown-linux-gnu)
I use autojump on OS X with zsh, so it also doesn't look like a zsh specific issue to me.
Aren’t you supposed to use autojump.zsh instead?
Though from what I see the only thing autojump.sh is doing is sourcing autojump.zsh or autojump.bash from some place so it should work with .sh. Work if maintainers of arch have patched autojump.sh: it does not expect to find autojump in /usr/etc.
If it does not work with autojump.zsh, post the output of doing (set -x ; source /usr/etc/profile.d/autojump.zsh).
There is no /usr/etc/profile.d/autojump.zsh pushed when autojump is installed via pacman. I don't know why this is the case.
However, I performed, manual user installation and added autojump plugin in my zsh configuration that takes care of sourcing the file.
I have tried above the ways,but I solved this problem by add the
source ~/.autojump/etc/profile.d/autojump.zsh
because the I have not find the /usr/etc/profile.d/autojump.zsh
I had repeated trouble with Autojump in ZSH regardless of sourcing the .zsh version. I never found a decent fix and eventually chose to stick with ZSH and stop using Autojump.
My personal solution was to switch from Autojump to FASD. It has the same functionality of Autojump via the 'z' alias. It also allows for specifically jumping to either a file or directory.
FASD has been a reliable part of my ZSH setup and surpasses the functionality of Autojump. I wrote up my experiences with FASD at greater length on my blog at Civet.ws