<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Lucky-Dip Blog</title>
    <link>http://blog.lucky-dip.net</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>ZSH</title>
      <description>&lt;p&gt;I've been zsh lately. I get the feeling most shells have similar features, but somehow I stumbled across a good config file for this one. It's so good I think it is worth sharing.&lt;/p&gt;

&lt;p&gt;
Features that I like in zsh:
&lt;ul&gt;
&lt;li&gt;Standard aliases, reverse search, history work as normal&lt;/i&gt;
&lt;li&gt;Typos in command names and directories are fixed automatically&lt;/li&gt;
&lt;li&gt;Auto 'cd' if you just type the directory name.&lt;/li&gt;
&lt;li&gt;Completion of command options (so the - and -- options!)&lt;/li&gt;
&lt;li&gt;Copletion of rake task names. This might the same as above, but it's still handy.&lt;/li&gt;
&lt;li&gt;Completion of remote paths over scp. It's a bit slow for regular use, but can be good if you've forgotten the name of one dir.&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;

So, my .zshrc is after the jump.

&lt;pre&gt;
###
# Autoload zsh modules when they are referenced
###
zmodload -a zsh/stat stat
zmodload -a zsh/zpty zpty
zmodload -a zsh/zprof zprof
zmodload -ap zsh/mapfile mapfile


###
# setup options
###
# use share_history instead of setopt APPEND_HISTORY         # appends history to .zsh_history
setopt AUTO_CD                # cd if no matching command
setopt AUTO_PARAM_SLASH       # adds slash at end of tabbed dirs
setopt CHECK_JOBS             # check bg jobs on exit
setopt CORRECT                # corrects spelling
setopt CORRECT_ALL            # corrects spelling
setopt EXTENDED_GLOB          # globs #, ~ and ^
setopt EXTENDED_HISTORY       # saves timestamps on history
setopt GLOB_DOTS              # find dotfiles easier
setopt HASH_CMDS              # save cmd location to skip PATH lookup
setopt HIST_EXPIRE_DUPS_FIRST # expire duped history first
setopt HIST_NO_STORE          # don't save 'history' cmd in history
setopt INC_APPEND_HISTORY     # append history as command are entered
setopt LIST_ROWS_FIRST        # completion options left-to-right, top-to-bottom
setopt LIST_TYPES             # show file types in list
setopt MARK_DIRS              # adds slash to end of completed dirs
setopt NUMERIC_GLOB_SORT      # sort numerically first, before alpha
setopt PROMPT_SUBST           # sub values in prompt (though it seems to work anyway haha)
setopt RM_STAR_WAIT           # pause before confirming rm *
setopt SHARE_HISTORY          # share history between open shells


###
# Setup vars
###
PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin/:$PATH"
TZ="Australia/Sydney"

HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
HOSTNAME="`hostname`"

export PAGER='less'
export EDITOR="mate_wait"
export GIT_EDITOR="mate_wait"
export PATH=$PATH:~/bin
export SHELL="/bin/zsh"

###
# Emacs shortcut keys
###
bindkey -e

###
# setup colours
###
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
  colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  (( count = $count + 1 ))
done
PR_NO_COLOR="%{$terminfo[sgr0]%}"


###
# ssh host completion
###
zstyle -e ':completion:*:(ssh|scp):*' hosts 'reply=(
  ${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) \
       /dev/null)"}%%[# ]*}//,/ }
  ${=${(f)"$(cat /etc/hosts(|)(N) &lt;&lt;(ypcat hosts 2&gt;/dev/null))"}%%\#*}
)'


###
# Aliases
### 

# general helpers
alias l="ls -laFhG"
alias m="mate ."
alias mw="mate -w"
alias myip="ifconfig | grep 192.168 || ifconfig | grep 10.32"
alias psg="ps ax | grep "
alias wget="wget -c"
alias top="top -o cpu"
alias mtop="top -o rsize"
alias sr="screen -r"

# rails helpers 
alias ss="rm -f log/development.log &amp;&amp; ruby script/server"
alias mdmu="rake db:migrate VERSION=0; rake db:migrate; rake db:test:clone"

# svn helpers
alias sst="svn st"
alias sup="svn up"
alias sci="svn ci -m "
alias si="svn propedit svn:ignore"
alias remove_missing='svn rm `svn st | grep \! | tr -d "! "`'
alias add_missing='svn add `svn st | grep \? | tr -d "? "`'
alias srp="svn propset svn:ignore '*.log' log/ &amp;&amp; svn propset svn:ignore '*.db' db/ &amp;&amp; svn propset svn:ignore 'schema.rb' db/"

# git helpers
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'


###
# get the name of the branch we are on
###
parse_git_branch() {
  git branch --no-color 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

###
# Called before prompt shown
###
function precmd {
  PS1="[$PR_MAGENTA%n$PR_NO_COLOR@$PR_GREEN%U%m%u$PR_NO_COLOR:$PR_CYAN%2c $PR_RED$(parse_git_branch)$PR_NO_COLOR]%(!.#.$) "
}

RPS1="$PR_MAGENTA(%D{%I:%M %p %d-%m-%y})$PR_NO_COLOR"








###
# Bunch of stuff I haven't figured out if I need yet
###
autoload -U compinit
compinit
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[[F"  end-of-line
bindkey "^[[4~" end-of-line
bindkey ' ' magic-space    # also do history expansion on space
bindkey '^I' complete-word # complete on tab, leave expansion to _expand

zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
    'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*:processes' command 'ps -axw'
zstyle ':completion:*:processes-names' command 'ps -awxho command'
# Completion Styles
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
# list of completers to use
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate

# allow one error for every three characters typed in approximate completer
zstyle -e ':completion:*:approximate:*' max-errors \
    'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
    
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
#
#NEW completion:
# 1. All /etc/hosts hostnames are in autocomplete
# 2. If you have a comment in /etc/hosts like #%foobar.domain,
#    then foobar.domain will show up in autocomplete!
zstyle ':completion:*' hosts $(awk '/^[^#]/ {print $2 $3" "$4" "$5}' /etc/hosts | grep -v ip6- &amp;&amp; grep "^#%" /etc/hosts | awk -F% '{print $2}') 
# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''

# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'

# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters

# command for process lists, the local web server details and host completion
#zstyle ':completion:*:processes' command 'ps -o pid,s,nice,stime,args'
#zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html'
zstyle '*' hosts $hosts

# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
    '*?.old' '*?.pro'
# the same for old style completion
#fignore=(.o .c~ .old .pro)

# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:scp:*' tag-order \
   files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:scp:*' group-order \
   files all-files users hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order \
   users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:ssh:*' group-order \
   hosts-domain hosts-host users hosts-ipaddr
zstyle '*' single-ignored show
&lt;/pre&gt;</description>
      <pubDate>Fri, 27 Jun 2008 14:01:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:de8990a6-ced4-4e1f-8bcd-49ff09ad8790</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/06/27/zsh</link>
      <category>zsh</category>
      <enclosure type="application/octet-stream" length="7343" url="http://blog.lucky-dip.net/files/zshrc2"/>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/12</trackback:ping>
    </item>
    <item>
      <title>performSelector in RubyCocoa</title>
      <description>&lt;p&gt;
I had a lot of trouble finding documentation for this. If you want to make a call on the main thread in RubyCocoa, the format is something like:
&lt;/p&gt;
&lt;pre class="code"&gt;
performSelectorOnMainThread_withObject_waitUntilDone('method_name:', object, true)
&lt;/pre&gt;

&lt;p&gt;
So two things that took me a while:
&lt;ol&gt;
&lt;li&gt;method_name has a trailing colon. &lt;/li&gt;
&lt;li&gt;The object the has the method you want to call should be the second argument. I got it in my head it should be the first for some reason.&lt;/li&gt;
&lt;/ol&gt;
&lt;/p&gt;

</description>
      <pubDate>Tue, 22 Apr 2008 15:01:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:dace920f-6826-4c1f-9893-6f7e58bcb965</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/04/22/performselector-in-rubycocoa</link>
      <category>ruby</category>
      <category>cocoa</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/11</trackback:ping>
    </item>
    <item>
      <title>Read table row-by-row in ruby</title>
      <description>&lt;p&gt;
I needed to export some data from a huge data table. Iterating through MyModel.find took too long and too much ram, so I went straight to the db instead. 
&lt;/p&gt;

Example code was tough to find, so here's an example:

&lt;pre class="code"&gt;
sql = "select * from #{ MyModel.table_name }"
MyModel.connection.execute(sql) do |handle|
  handle.fetch do |row|
    # row is an array of values
    ... export row ...
  end
end
&lt;/pre&gt;

</description>
      <pubDate>Wed, 12 Mar 2008 12:00:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:7f1cc0c7-4146-4e78-ab19-e968710cb720</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/03/12/read-table-row-by-row-in-ruby</link>
      <category>ruby</category>
      <category>rails</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/10</trackback:ping>
    </item>
    <item>
      <title>Named SQL Server Instances with FreeTDS</title>
      <description>&lt;p&gt;
&lt;a href="http://permalink.gmane.org/gmane.comp.db.tds.freetds/9182"&gt;A helpful post on accessing named sql server instances using freetds&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
I was having a lot of trouble doing that. Turns out the 'instance' key exists. As far as I could find it wasn't in the doc anywhere, so this is just a post in the hope that it'll save somebody else some time in the future.
&lt;/p&gt;

From the post:
&lt;pre class="code"&gt;
[def]
host = abc
instance = def
port = 1433
client charset = UTF-8
tds version = 8.0
&lt;/pre&gt;





</description>
      <pubDate>Mon, 10 Mar 2008 19:31:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:0b47ce36-fb23-4ab6-8d1e-249426f695dd</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/03/10/named-sql-server-instances-with-freetds</link>
      <category>freetds</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/9</trackback:ping>
    </item>
    <item>
      <title>Using Javascript Code for RJS Instead of IDs</title>
      <description>Some info on how to make RJS output code like:
&lt;pre&gt;&lt;code class="ruby"&gt;
new Insertion.Bottom($$('p.welcome b').first(), "Some item"
&lt;/code&gt;&lt;/pre&gt;
&lt;a href="http://sentia.com.au/2008/03/using-javascript-code-for-rjs.html"&gt;http://sentia.com.au/2008/03/using-javascript-code-for-rjs.html&lt;/a&gt;

</description>
      <pubDate>Mon, 05 Nov 2007 12:31:00 +1100</pubDate>
      <guid isPermaLink="false">urn:uuid:6b38ca78-8f3b-4eb0-b3a5-9c95cce806e9</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2007/11/05/using-javascript-code-for-rjs-instead-of-ids</link>
      <category>rails</category>
      <category>rjs</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/8</trackback:ping>
    </item>
    <item>
      <title>Redish Greenish for ZenTest</title>
      <description>&lt;p&gt;
&lt;a href="http://www.zenspider.com/ZSS/Products/ZenTest/"&gt;ZenTest&lt;/a&gt; is a great tool. I use it and its redgreen plugin a lot to easily keep an eye on my tests.
&lt;/p&gt;

&lt;p&gt;
I use a green terminal background though, so when my tests pass, rather than a green line, I have to rely on a lack of a red line. This isn't so bad, but I thought it could be improved with a little effort.
&lt;/p&gt;

&lt;p&gt;
Redish greenish is an extension of redgreen that allows you to specify the colours used for tests passing and/or failing.
&lt;/p&gt;

&lt;p&gt;
To use it, &lt;a href="http://blog.lucky-dip.net/files/redishgreenish.rb"&gt;save this file&lt;/a&gt; into your autotest lib directory. (Mine is GEM_PATH/1.8/gems/ZenTest-3.6.1/lib/autotest/). To enable redishgreenish, you'll need to modify your autotest config file. Open "~/.autotest" and change the line:
&lt;br /&gt;
&lt;code&gt;
require 'autotest/redgreen'
&lt;/code&gt;
&lt;br /&gt;
to 
&lt;br /&gt;
&lt;code&gt;
require 'autotest/redishgreenish'
&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
At this point, autotest will behave exactly the same as if redgreen was used. To change the colour of the lines used to signify tests passing and failing, your autotest config file should look like
&lt;br /&gt;
&lt;code&gt;
PASSED = :blue
&lt;br /&gt;
FAILED = :yellow
&lt;br /&gt;
require 'autotest/redishgreenish'
&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
Valid values for colours are
&lt;br /&gt;
&lt;code&gt;
:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white
&lt;/code&gt;
&lt;/p&gt;

</description>
      <pubDate>Sat, 29 Sep 2007 13:26:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:3a006676-a8cc-48ec-898e-f37123a6071b</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2007/09/29/redish-greenish-for-zentest</link>
      <category>zentest</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/7</trackback:ping>
    </item>
    <item>
      <title>Haml &amp;amp; Sass Editors 0.5.4</title>
      <description>&lt;p&gt;Last release didn't go so well. For some reason I figured other people had tried to install Aptana, had it fail and then given up on it like me. Turns out I was alone haha.&lt;/p&gt;

&lt;p&gt;
So I spent a bit of time figuring out what changed in RDT and fixed things up. I've tested this with a straight out of the box install of Aptana m8, so hopefully it'll work for others too.&lt;/p&gt;

&lt;p&gt;
If anybody does try it, please let me know if it works or not. I'm going to use this blog post as a bit of a test before I post to the Haml mail list. Thanks in advance to anyone who replies!&lt;/p&gt;

&lt;p&gt;
(Oh yeah, the update site is still http://haml.lucky-dip.net/).
&lt;/p&gt;

</description>
      <pubDate>Fri, 06 Jul 2007 13:49:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:00d5ee5e-3e09-4444-b336-2fc237360171</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2007/07/06/haml-sass-editors-0-5-4</link>
      <category>haml</category>
      <category>sass</category>
      <category>aptana</category>
    </item>
    <item>
      <title>Haml &amp;amp; Sass Editor For Eclipse</title>
      <description>&lt;p&gt;
I did some very basic editors for Haml and Sass a while back. At the time I was interested in Haml. It's elegant to write, and the automatically formatted html it outputs just made it a match made in heaven.
&lt;/p&gt;
&lt;p&gt;
Fast forward a few months and now I'm actually using Haml and Sass. It's as good as I ever hoped it would be. With Haml and a little bit of FormBuilder magic I'm making useful forms in four short lines. Too good.
&lt;/p&gt;
&lt;p&gt;
Anyway coming with using it is the chance to see some shortcomings in my own editors, so I've spent a bit of time updating them. I've set up a proper Eclipse update site, so you can just add 'http://haml.lucky-dip.net' via the 'Help - Software Updates - Find and Install' menu option. That should help minimize a few errors with the various versions of Eclipse and RDT around. All references to the RadRails plugins have been removed. There was a bit of code that I pulled into my plugin, but with RadRails/Aptana in heavy dev it's easier for me to forget about trying to keep up for a while.
&lt;/p&gt;
&lt;p&gt;
Also added is code folding. There's a bit of work still to do on this one. You can currently only fold top level elements. This can be a pain when you've got all your code in one file, but if you're using layouts and partial in a sensible way it should hopefully be of some use. 
&lt;/p&gt;
&lt;p&gt;
One thing I found a bit tricky was figuring out which element I was under when I was editing. Some people might like turning on space markers (can you actually do that in Eclipse?), but I figured a character matcher would do the trick. So now as you move around in the editors there'll be a blue box around the element you are currently in. At the moment it just highlights the first letter of the element. I'm going to see if I can get the whole element happening for the next release.
&lt;/p&gt;
&lt;p&gt;
So I hope it works well for people. Set up an Eclipse update site of 'http://haml.lucky-dip.net' and that should keep you informed as new versions come out.
&lt;/p&gt;

</description>
      <pubDate>Sun, 24 Jun 2007 14:58:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:e00587d0-2429-495a-8a8a-29846c3372ab</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2007/06/24/haml-sass-editor-for-radrails</link>
      <category>haml</category>
      <category>sass</category>
      <category>eclipse</category>
      <category>radrails</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/1</trackback:ping>
    </item>
  </channel>
</rss>
