qrush / sub

a delicious way to organize programs
http://37signals.com/svn/posts/3264-automating-with-convention-introducing-sub
MIT License
1.74k stars 148 forks source link

zsh: occasionally seeing "command not found: complete" when loading subs #31

Closed bradical closed 11 years ago

bradical commented 11 years ago

I'm using:

and am sometimes seeing the following errors when opening new terminal windows or tabs:

/Users/bradley/Dropbox/bin/csd/libexec/../completions/csd.bash:14: command not found: complete
/Users/bradley/Dropbox/bin/sp/libexec/../completions/sp.bash:14: command not found: complete
/usr/local/Cellar/rbenv/0.3.0/libexec/../completions/rbenv.bash:14: command not found: complete

I'm assuming rbenv is also a sub so this is probably related.

The only thing I've noticed is that when my terminal profile is set to change into a particular directory on load, this tends to happen.

Here's the relevant portion of my .zshrc file:

... stuff before the end of the file ...
plugins=()

. ~/Dropbox/bin/z/z.sh
source ~/Dropbox/bin/ssh.bash
source ~/Dropbox/bin/mysql.bash
source ~/Dropbox/bin/du.bash

eval "$(/Users/bradley/Dropbox/bin/csd/bin/csd init -)"
eval "$(/Users/bradley/Dropbox/bin/sp/bin/sp init -)"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi # rbenv, ruby-build

source $ZSH/oh-my-zsh.sh

Any ideas?

bradical commented 11 years ago

Sorry, for the vague description. Figured someone might have seen this before. Seems like maybe a problem about the order in which things are loaded perhaps?

bradical commented 11 years ago

I've noticed that when that error does occur, the completions are not enabled on that particular Zsh session. The odd thing is that it doesn't happen all the time.

mislav commented 11 years ago

If you have zsh, then bash completions shouldn't get sourced. Because rbenv init (and other programs, evidently) thinks you're using bash, it means your $SHELL value is wrong. It should be "/bin/zsh", but is probably "/bin/bash".

This can happen if you've launched zsh from a bash session. Is zsh your login shell? Do you ever start bash? Can you grep for "SHELL" in your init files?

bradical commented 11 years ago

Strange. I used chsh -s /bin/zsh to set my shell to zsh.

But you're absolutely right: in the windows where it works:

$ echo $SHELL
/bin/zsh

and in the windows where I get the warning:

$ echo $SHELL
/bin/bash

even though both windows appear to be running zsh. Must be something weird with ITerm2 when using a profile that specifies a starting directory. I'll poke around.

Thanks!

OscarGodson commented 11 years ago

@bradical did you ever figure this out? I'm using iTerm too and have

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

and but can't seem to figure it out...

duderman commented 9 years ago

@OscarGodson try to set SHELL env variable in .profile or somewhere else before eval "$(rbenv init -)"

cweagans commented 8 years ago

This should be reopened. $SHELL is only the default shell. It doesn't actually tell you with 100% certainty what the current shell is. Usually, they're they same, but if you run zsh as a subprocess of bash (for testing or whatever), you'll see this error. In my case, it was because iTerm was handling this option in a strange way - I think it was starting a bash shell, then running the command inside of a bash shell. $SHELL, then, was set to /usr/local/bin/bash in zsh. (I intend to switch my login shell to zsh, but for now, I'm using Terminal.app for day-to-day stuff while I get zsh configured. I can then test my config in iTerm, hence the odd setup).

The solution here is to harden the shell detection bits in sub-init. I suggest checking for $BASH and $ZSH_NAME. Those variables will be set on their respective shells