#309 A Shell-Scripting Story pro
Dec 19, 2011 | 10 minutes |
Tools
This episode continues off of the previous episode on Oh My ZSH showing how to script Z Shell. Here I show how to write a Rake autocompletion script and cover a few more useful utilities.
- Download:
- source codeProject Files in Zip (991 Bytes)
- mp4Full Size H.264 Video (19.2 MB)
- m4vSmaller H.264 Video (11.1 MB)
- webmFull Size VP8 Video (11.8 MB)
- ogvFull Size Theora Video (23.8 MB)
Great episode!
I had to modify the rake autocompletion a bit to suppress an error "No such file or directory .rake_tasks~" in a directory that didn't contain .rake_tasks~ already.
Just directed standard error to /dev/zero (or it would be /dev/null if you are on a linux box)
http://pastie.org/3041568
The custom/plugins/rbates/rbates.plugin.zsh file is required, ok if it's empty.
Might want
setopt cshnullglob nullglob
in your .zshrc as well to avoid wildcard errors bombing the script.As I am stuck on windows 7 for a lot of reasons, I feel a bit left out this week.
I have the same problem I found out that ZSH (and oh-my-zsh) works in windows under cygwin which emulates a *nix environment. It's a little bit slower, and i had some quirks buts its worth a try.
Thanks for sharing this, particularily the rake completion part. Any plans for pushing this back to the upstream maybe?
+1
I find it useful when you mention books to look at if someone wanted to dig deeper into the subject. Please continue doing that. Thanks Ryan!
I've been using zsh for about a year, and recently tried writing my own compdef scripts, but got bogged down in the docs. This screencast has really helped things click in my mind. Thanks, Ryan!
may I suggest changing the line: local recent=$(ls -t .rake_tasks~ Rakefile */.rake | head -n 1) to local recent=$(ls -t .rake_tasks~ Rakefile */.rake 2>/dev/null | head -n 1)
It removes error output for .rake_tasks~ not existing.
Thanks for excellent screencast. It's mind boggling to think how long Ryan has been producing these and never missing a week. Really stunning achievement. Thanks to this screencast I'm actually now trying out zsh and it feels really nice. There are loads of powerfull features.
Although I have to say that documentation you find via google can really bog you down. So this screencast really helped.
One noticeable difference I encountered is expansion of '..' and '~'. If I'm in subdirectory and want to touch/edit file higher on directory tree I usually type something like:
touch .. (this expands the prompt into: touch ../)
zsh doesn't seem to do that kind of expansion. Also hittin after typing ~ doesn't expand ~ into johndoe/ or ~/
At this point everyone with US keyboards are probably wondering why this is such a big deal? Well with scandinavian layout '/' is achieved with SHIFT+7 which is way more painfull to do instead of with your little-finger.
Trying to google for solution but if anyone has quick fix please let me know!
Great tuto ! Useful for everythin. Thanks
Please note that it should be :
and not
Hey I like the idea for this and tried it on my system but something is broken. I am on Ubuntu 11.04 and when I try auto completion after rake it takes a while to load and then shows no options unless there are file names in the directory that I am in that begin with rake. Just no db:create or any thing like that. It was like this before and after I added the _rake to the custom directory. Do I need to add rake or _rake to the plugin call in .zshrc? Thanks for your help I am really enjoying your rails cast.
Switching branches often makes the rake completion somewhat less usable. So I changed it up a bit to use the md5 sums of all the rake files instead of looking at timestamps:
This will leave a bunch of .rake_tasks.[...]~ files around so the fast completion will continue to work even when switching between branches that have different rake files.