marlonrichert / zsh-autocomplete

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
MIT License
5.32k stars 147 forks source link

Don't break when sourced more than once #41

Closed srappan closed 4 years ago

srappan commented 4 years ago

This occurs whenever I source my ~/.zshrc with this plugin

❯ zshreload
_autocomplete.add-zsh-hook:1: job table full or recursion limit exceeded
    ~                                                                                                                                     ✔  12:59:36  
    ~  e_main_complete:208: command not found: 3174                                                                                       ✔  12:59:39  
_main_complete:208: command not found: 3174
_main_complete:208: command not found: 3174
_main_complete:208: command not found: 793
_main_complete:208: command not found: 793
_main_complete:208: command not found: 793
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
e_main_complete:208: command not found: 3174
_main_complete:208: command not found: 3174
_main_complete:208: command not found: 3174
_main_complete:208: command not found: 793
_main_complete:208: command not found: 793
_main_complete:208: command not found: 793
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
e

My .zshrc

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/home/shash/.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/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"

# 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"
#complete setup zsh | source /dev/stdin
# 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=1

# 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

#source /usr/share/fzf/completion.zsh
#source /usr/share/fzf/key-bindings.zsh
# 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=(
zsh-syntax-highlighting
git
fzf
zsh-autosuggestions
zsh-autocomplete
docker
npm
yarn
history-substring-search
zsh-completions
encode64
pip
pyenv
python
sudo
autoupdate
)

source $ZSH/oh-my-zsh.sh
export QT_QPA_PLATFORMTHEME=qt5ct
# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
export LANG=en_GB.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"
alias weather="curl wttr.in/Cardiff"
alias zshreload="source ~/.zshrc"
#export EDITOR="nano"
# Completion for kitty
kitty + complete setup zsh | source /dev/stdin

#autoload -Uz compinit
#compinit

autoload -U compinit && compinit
# Import colorscheme from 'wal' asynchronously
# &   # Run the process in the background.
# ( ) # Hide shell job control messages.
#(cat ~/.cache/wal/sequences &)
# Alternative (blocks terminal for 0-3ms)
#cat ~/.cache/wal/sequences
# To add support for TTYs this line can be optionally added.
#source ~/.cache/wal/colors-tty.sh
(cat $HOME/.config/wpg/sequences &)

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
marlonrichert commented 4 years ago

You have a lot plugins installed. Can you please disable them one by one to see which one it is that conflicts with zsh-autocomplete? Then I can investigate the conflict and fix it.

srappan commented 4 years ago

Disabled everything except fzf, zsh-syntax-highlighting, zsh-autosuggestions, zsh-autocomplete. Still the same error.

❯ source ~/.zshrc
_autocomplete.add-zsh-hook:1: job table full or recursion limit exceeded
    ~  d_main_complete:208: command not found: 1936                                                                                       ✔  13:25:47  
_main_complete:208: command not found: 1936
_main_complete:208: command not found: 1936
_main_complete:208: command not found: 485
_main_complete:208: command not found: 485
_main_complete:208: command not found: 485
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
_main_complete:208: command not found: ''
d
marlonrichert commented 4 years ago

@srappan You must still have some other customization enabled, because I just did a clean install of OMZ + fzf, zsh-syntax-highlighting, zsh-autosuggestions and zsh-autocomplete, and it worked fine.

srappan commented 4 years ago

I have powerlevel10k installed too, the error only occurs after sourcing the .zshrc

marlonrichert commented 4 years ago

Wait, why are you sourcing your .zshrc file? That file already gets sourced automatically when your shell starts up.

srappan commented 4 years ago

To reload .zshrc when I make a change to the file

marlonrichert commented 4 years ago

OK, thanks. I'll see if I can somehow make sure that zsh-autosuggest doesn't run again when you re-source your .zshrc file, because that's what's happening now.

NICHOLAS85 commented 4 years ago

It is generally not a good idea to source your .zshrc during your session to reload your config as errors such as the one you’re running into tend to occur. Many plugins do not account for loading twice in the same session which is why you may see issues after sourcing. It is normally recommended to restart you session to apply changes such as running exec zsh

olets commented 4 years ago

Getting a similar (on the user end anyway) error:

# ~/.zshrc, nothing installed except zinit

zinit light marlonrichert/zsh-autocomplete
% source ~/.zshrc
_autocomplete.add-zsh-hook:4: cannot duplicate fd 1: too many open files

 

Many plugins do not account for loading twice in the same session which is why you may see issues after sourcing. It is normally recommended to restart you session to apply changes such as running exec zsh

I've never had trouble with other plugins, or heard this recommendation. Which isn't to say there aren't other plugins that have this bug or that no one uses exec zsh but I do think it's reasonable for a user to expect to be able to source the shell rc

marlonrichert commented 4 years ago

@olets And that's why I'm keeping this issue open until I've fixed it. 🙂 But it's going to take time. zsh-autocomplete is a fairly complex plugin. It's not immediately obvious how to solve this.

marlonrichert commented 4 years ago

I've never had with other plugins, or heard this recommendation.

@olets I'm not the only one who says so: https://github.com/romkatv/powerlevel10k/blob/master/README.md#weird-things-happen-after-typing-source-zshrc

It's almost always a bad idea to run source ~/.zshrc, whether you are using Powerlevel10k or not. This command may result in random errors, misbehaving code and progressive slowdown of Zsh.

If you've made changes to ~/.zshrc or to files sourced by it, restart Zsh to apply them. The most reliable way to do this is to type exit and then start a new Zsh session. You can also use exec zsh. While not exactly equivalent to complete Zsh restart, this command is much more reliable than source ~/.zshrc.

marlonrichert commented 4 years ago

Available now on master.