command line - How do I get the aws cli completion to work with zsh on ubuntu?
2014-07
I installed aws console cli following the instructions here:
http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#install-bundle-other-os
I want to get completion working with zsh. The instructions say to source bin/aws_zsh_completer.sh
, which I don't see in the downloaded uncompressed zip installer.
I went ahead and cloned the git repo locally.
Still, sourcing the file doesn't work out of the box. When I attempt to autocomplete, I get python errors complaining about missing modules etc. (e.g., ImportError: No module named awscli.completer
)
What am I missing here?
I am using Robby Russell's "oh-my-zsh" extension on OSX 10.5 Leopard. However I find that it's not loaded by default.. when I start a new Terminal it uses the "default" ZSH prompt, and I must manually type "zsh" and press Return to get the "enhanced" prompt. My .zshrc
file lists the ZSH path as pointing to the oh-my-zsh directory:
This gets very annoying because every time I open a new tab I've got to type zsh again (as an aside is it possible to get a new tab to remember my current working directory? I mainly write Rails apps so I'll have 2-3 windows open inside the same directory and it's frustrating to have to cd back into it every time). Is there an easy way to get it automatically start oh-my-zsh when I open a terminal so I don't have to type zsh every time?
EDIT
I automatically installed oh-my-zsh following Robby's instructions on Github, so here's the .zshrc it created for me:
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set to the name theme to load.
# Look in ~/.oh-my-zsh/themes/
export ZSH_THEME="maran"
# Comment this out to disable weekly auto-update checks
# export DISABLE_AUTO_UPDATE="false"
source $ZSH/oh-my-zsh.sh
# Customize to your needs...
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr /local/bin:/usr/X11/bin:/usr/local/git/bin
export GIT_EDITOR="mate -w"
I tried changing the default shell to point to that but then I get an error saying it's been set to an illegal variable. The $HOME variable points correctly to my home directory, but it doesn't seem to be loading until I type zsh in the terminal when I have the regular zsh prompt.
EDIT
Here is the output of pstree -wp $$
-+= 00001 root /sbin/launchd \-+= 00066 waynemolina /sbin/launchd \-+= 68844 waynemolina /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal -psn_0_704684 \-+= 68845 root login -pfq waynemolina /bin/zsh \-+= 68846 waynemolina -zsh \-+= 68939 waynemolina pstree -wp 68846 \--- 68940 root ps -axwwo user
Back in 10.4, Terminal has a preference for “When creating a new Terminal window” to either use /usr/bin/login
or to let the user specify a command. I expect that Terminal in 10.5 has something similar.
Do you happen to have something like zsh -f
as the specified command instead of using /usr/bin/login
or a zsh invocation without -f
? The -f
option will cause zsh to ignore all the startup files except /etc/zshenv
(i.e. it will ignore your ~/.zshrc
).
Another way to check this setting might be with defaults read com.apple.Terminal Shell
. If it shows some output you have a custom setting. If it is blank or does not exist then you are probably still using the default of /usr/bin/login
.
Edited to add:
In one of your shells with the default prompt (a new Terminal window or tab), check for the following:
- Does
set -o | fgrep rcs
show “on” fornorcs
? - Does
[[ "$ZDOTDIR" -ef "$HOME" ]] || echo "ZDOTDIR=$ZDOTDIR"
show anything?
If one or both of these conditions are true, you'll need to track down where they are being set. Note that norcs
might be set with any of set +o rcs
, set -o norcs
, setopt norcs
, unsetopt rcs
, or set -f
. Also the option names are not case sensitive and may have underscores inserted anythere (NO_rC___s
is the same as norcs
). Look in /etc/zshenv
, /etc/zprofile
, /etc/zshrc
, /etc/zlogin
; and .zshenv
, .zprofile
, .zshrc
, and .zlogin
from your ZDOTDIR directory.
It might also be useful to know the full parentage of your “default prompt” shells (pstree -wp $$
if you have pstree
from (e.g.) MacPorts). Maybe the normal ‘rc’ process is being interrupted by something like zsh -f
in an ‘rc’ file.
I don't know too much about how Mac OS X works with shells, but in general I find it useful to sprinkle some echo statements around my initialization files, to make sure that they are being sourced. So, in your .zshrc file, you could put a line that says echo "Loading .zshrc"
. And so on. The presence or absence of these echo statements when you start a new shell (or open a new tab) should help you diagnose the problem.
As for the directory changing problem, there are two potential solutions:
1. Use screen, and forget about tabs.
2. Write a function to echo the current directory to a file somewhere, then put that function in your precmd, and then add a line in .zshrc to read that file and cd to it. To be more specific (but untested!):
PWD_SAVE_FILE="$HOME/.pwd_save"
function savepwd {
pwd > "$PWD_SAVE_FILE"
}
function precmd {
savepwd
}
cd "`cat "$PWD_SAVE_FILE"`"
I had this problem. It was due to having a .zlogin in my home directory. Once I removed .zlogin oh my zsh worked
Try putting this in your ~/.zshrc
file for debugging purposes:
Right after this line:
export ZSH=$HOME/.oh-my-zsh
Put:
echo $HOME
echo $ZSH