#308 Oh My ZSH
Dec 19, 2011 | 9 minutes |
Tools
As Rails developers, we frequently use the command line. Here I will show how to switch to Z Shell using Oh My ZSH including how to make your own theme and plugins.
- Download:
- source codeProject Files in Zip (2.18 KB)
- mp4Full Size H.264 Video (25.9 MB)
- m4vSmaller H.264 Video (11.2 MB)
- webmFull Size VP8 Video (11.7 MB)
- ogvFull Size Theora Video (23.5 MB)
Yippi! It just crashed my environment... I'm using rvm if that makes a difference:
Any Ideas?
I'm getting the same error, don't know how to fix it.
I'm closing in on it. rvm seems to forget which ruby to use.
"rvm system ruby-1.9.2-p290" is a small fix even though it does not fix this entirely...
The reason is that your
.bash_profile
is no longer loaded with zsh. Put these two lines at the end of.zshrc
and it will work again (of course you need to adapt the path to your home dir and the desired ruby version):More solutions on rails-troubles.com ;)
Yep, figured that one out yesterday. Thanks anyway! Any chance to not include the ruby version in the file and to let rvm handle the versioning?
Yes, just run
rvm --default use 1.9.2
once. I think thervm 1.9.2
line in my script just remained because I had troubles setting the default ruby version some time ago.If your name isn't Clemens, you should use the generic form :)
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
It doesn't work dude. When I open my terminal, I get this errors .
Unknown ruby interpreter version (do not know how to handle): textmate.
Could not load ruby textmate.
{18:20}[1.9.3]~ ➭
And in my .zshrc file, I have add this line of code
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
Its doesn't change any more.
I have try this but still I am getting same error.
Unknown ruby interpreter version (do not know how to handle): textmate.
Could not load ruby textmate.
{18:20}[1.9.3]~ ➭
And in my .zshrc file, I have add this line of code
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
For me this worked:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
That dot is necessary.
Check your PATH (export PATH) in .zshrc and remove all references to .rvm within it. You should end up with something like this export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin
When installing oh-my-zsh it will look at your current PATH and fill your .zshrc with it, which also pulls .rvm environment. And you won't want that there since rvm should be handling it.
This worked awesome, thanks. It turns out oh-my-zsh added a ton of stuff to my path!
+1 I just found this out myself and came here to see if anyone mentioned it. It's too bad the RVM site doesn't have a wiki. It's closed nature is beginning to be a sore point for me, especially because it seems to have quite a few gaps since Lion. I almost switched to RBEnv over this.
Been finding the solution online for a while. Most of them give the adding the if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi which is a must have.
Even after adding this line , rails still errors. I have to remove .rvm association from export path like you mention here. Solved!
Hi Ryan.
Regarding to your c() _c() example, you can do the same thing just doing :
cdpath=(. ~/Railscasts)
It adds given paths to current directory path so all files and directories in ~/Railscasts are available from anywhere just typing : cd some_dir_in_railscasts_dir
That's a native future of ZSH so why bother reimplementing it.
I don't care for this feature as much. It's a bit too greedy. Primarily because every time I try to do autocompletion it will try to use the directories there.
That's true, cd doesn't handle autocompletion in cdpaths.
Anyways, I use omz for looking up interesting solutions. I like to keep my shell environment small.
I'm already using the dotfiles from ryans github site. Is it worth for me to switch to using this and have to move all my custom stuff?
I worry that approaching zsh like this will be like approaching vim via Janus. When I was a Janus user I couldn't tell you what was a feature of Janus' configuration or plugins and what was a native feature of vim. It wasn't until I started my own vim configuration from scratch that I really started to understand what was going on.
Fair point, but I think that cost is worth it for the ease of transition.
Once one starts to get their feet wet and become curious about separating Oh My ZSH from ZSH they can browse the
~/.oh-my-zsh/lib
directory and it's quite easy to see all that it is configured.OH MY! It has broken my rvm differently from 4ware's report.
upon opening a shell, if I try to access a gemset like I usually do:
rvm @myapp
I get the following:Has this happened to anyone else?
Thanks!
thx for this episode - I'm leaving bash for greener pastures.
Question: Anyone know what the
%p
escape is doing in the default prompt? Here's the whole thing:I don't see any references to
%p
inman zshmisc
and it doesn't seem like anything is being displayed there on any of my prompts... Anyway, just a curiosity.I was actually wondering the same. I found something here that says it should show the time:
But it doesn't work for me either, so I simply removed it (not that I would want the time shown on each and every command line).
Thanks for re-introducing ZSH to me, Ryan. I used to use zsh but got lazy when I switched to a new machine. On bash, I used bash_it for adding zsh like capabilities to bash. One of the plugins I really liked is z-zsh (https://github.com/sjl/z-zsh). I just added it to my custom set of plugins.
As an FYI, I use ZSH in windows with cygwin just fine. It's definitely slower than under *nix, but it works and makes windows development much more... possible. You'll need to use the manual install method, however.
I really like how easy it is to add highlighting to my prompt. Incase anyone is interested in some basic color configuration look at my gist.
If nothing is running when I open a new tab (cmd + t) from ZSH, it is in the directory of the previous tab. However, if my rails server is running and I open a new tab, it defaults to my home directory. Any suggestions on how to get consistent behaviour? I would prefer to always have the previous tabs location.
+1 for same problem.
Not only when rails s running, but also any programs like vim. If I hit cmd + t when inside vim, the new tab is at home directory.
Same here. I'll post if I figure something out.
@rbates
Is the "rbates.zsh-theme" shown in this screencast the theme you use in virtually all of your screencasts? If not, please show us "the original - the one and only rbates zsh-theme".
Thank you :)
Thanks Ryan, another great Railscast.
For the people commenting about oh-my-zsh vs. vanilla zsh, I highly recommend Thoughtbot's dotfiles scripts, sets up a very nice zsh environment as well as an awesome .vimrc + vim plugins.
Does this install zsh for iTerm2? Or will this only work for Terminal users?
Shells (like zsh) are a system-wide thing, so I don't think the terminal client you choose should matter. I setup zsh once and it run the same way in both Terminal and Coda, so I would be pretty surprised if it didn't also run in any other terminal client (iTerm2).
How do you get the delete key to work on a Macbook pro? The default key binding sends something other than delete. Adding bindkey "^[[3~" delete-char to a custom config file doesn't do it.
Edit: The delete key seems to be deleting one character at a time as it should, but the cursor moves forward when it is hit--very confusing. Am I the only one seeing this?
Edit: Okay, so declaring my terminal as 'vt100' instead of 'xterm-color' as it was before appears to fix the delete cursor issue along with a couple of other oddities.
Anyone having issues with rspec/cucumber no longer printing out colors after zsh install?
Anyone having issues with vim and gui mode?
When I open vim in terminal it says:
CSApprox needs gui support - not loading
Any idea how to make it with gui support?
Hi there,
My Term stays white backgrounded, colors change, but not all,
only if I switch the theme in OS X Terminal Settings to another term,
then the theme switches to the text and terminal color of OS X choice.
anyone knows, why colors are not switched properly?
Check this out http://stackoverflow.com/questions/14056007/oh-my-zsh-themes-dont-show-properly-background-stays-white
Hi Ryan,
i've installed your dot files on my other machine the other day. The plugins dir does nit seem to be loaded. Where shall i put my custom plugins?
I am new to Mac but I noticed that you don't need zsh to have the feature that whenever you open a new tab in the terminal, it will land in the same directory from which you make the new tab. Does anyone else also get that?
That's new in OSX Lion.
RVM has a helpful page on integration with ZSH:
http://beginrescueend.com/integration/zsh/
It recommends not using the ZSH bundler plugin and adding __rvm_project_rvmrc to the bottom of .zshrc if using iTerm2+"Reuse Previous Tab's Directory"
Anyone else having trouble with shortcuts in zsh on Lion? eg after keying option-b (go back one word), other shortcuts like ctrl-e (go to end) no longer work. Delete and option-delete don't work at all. Terminal is configured with "Use option as meta key" checked. I tried @ErikHick's vt100 suggestion but that didn't help. I'm not using oh-my-zsh, just plain zsh with thoughtbot/laptop settings.
Found the problem:
This enables "vi mode", meaning vi command mode is activated when esc (or meta/option) is pressed. Comment this line out to revert to regular bash shortcuts.
For people having problems installing it on Fedora (15/16 Live CD) and my own future reference:
note: the curl version somehow did not work on my Fedora 16 (it worked on Fedora 15 though)
which zsh => /bin/zsh
chsh -s /bin/zsh
or just chsh and choose the shell.
Logout / Restart
change .zshrc as mentioned by Ryan.
Copy rvm specific stuff from .bashrc to .zshrc
rvm --default use gemsetname (e.g 1.9.2@rails3)
Hi Ryan,
thanks for this Railscast, loving zsh.
But I would certainly add a note regarding Railscast #66 Custom Rakes. You need to add this in the .zshrc file:
alias rake="noglob rake"
I was using zsh for a while when I first needed to use a custom rake command with parameters I had built. I couldn't figure what was wrong and it took me a while to see that it was not an error in the rake file.
Thanks
Fred
Hi! Another great episode Ryan :)
I've just watched this (a little late I know) and after installing
oh-my-zsh I noticed that I lost access to the history on interactive ruby console and also rails console. I remember (maybe I'm wrong) that after I closed a rails console session, I was able to access the last commands via the arrow keys when a new session was started.
Is it me o oh-my-zsh can't handle this? Isn't a big deal, just curious if is it possible.
Thanks again :)
I've seen a lot of confusion about the various initialization files for shells. So I wanted to share the Startup Files page from zsh.sourceforget.net:
$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout
Ryan, I assume you used iTerm2 before you switched back to the OSX Terminal? If so, this option for preserving the directory you were in, can be done in iTerm2 also, it's in Preferences - Profile - General - Working Directory - Advanced Configuration (There I set it to $HOME when opening new windows and to the previous sessions directory on new tabs and split panes. :-)
I needed to use chsh to change the default shell after installation:
chsh -s /bin/zsh
I also installed zsh itself using homebrew and oh-my-zsh afterwards via the wget. It's kind of silly that oh-my-zsh isn't just in homebrew.
Any other plugins you guys like?
In case anyone else had trouble maintaining the current directory when opening a new tab, I wrote the following plugin:
Then just call the plugin in your
.zshrc
If you're having a problem where the theme's prompt isn't displaying correctly, just check you haven't brought in an errant PS1 prompt from your .bash_profile (or elsewhere)