Commit 4b19a3cabc5e01932e56930a402767268dff8925

Tools for finding and working with rails projects in your home dir (with tab completion, of course).

rdir project: Resolve project to path
rcd project: Changes working directory
rmate project: Opens project in Textmate

Run "rdir clean" to clear the cache.

Commit diff

completions/rcd.fish

 
1complete -x -c rcd -a '(rdir | sed -e "s/\/.*\///g")' --description 'Rails Project'
toggle raw diff

completions/rmate.fish

 
1complete -x -c rmate -a '(rdir | sed -e "s/\/.*\///g")' --description 'Rails Project'
toggle raw diff

functions/rcd.fish

 
1function rcd -d "Search for rails project and change dir"
2 if test $argv
3 set dir (rdir $argv)
4 if test $dir
5 cd $dir
6 else
7 echo "Cannot find any project named '$argv'"
8 end
9 else
10 echo "Usage: rcd <project>"
11 end
12end
toggle raw diff

functions/rdir.fish

 
1function rdir -d "Find dir for rails project"
2 if test "$argv" = "clean"
3 for a in /tmp/rdir_cache/*
4 rm "$a"
5 end
6 echo "Cache cleaned"
7 else
8 if test "$argv"
9 set -l hashed_project (md5 -q -s "$argv")
10 set -l rdir_cache_file "/tmp/rdir_cache/$hashed_project"
11 if not test -f "$rdir_cache_file"
12 find ~/**/$argv/config/environment.rb | head -n 1 | sed -e 's/\/config\/environment.rb$//g' > "$rdir_cache_file"
13 end
14 cat "$rdir_cache_file"
15 else
16 set -l rdir_cache_file "/tmp/rdir_cache/all_projects"
17 if not test -f "$rdir_cache_file"
18 mkdir -p "/tmp/rdir_cache"
19 find ~/**/config/environment.rb | sed -e 's/\/config\/environment.rb$//g' > "$rdir_cache_file"
20 end
21 cat "$rdir_cache_file"
22 end
23 end
24end
toggle raw diff

functions/rmate.fish

 
1function rmate -d "Search for rails project and open in Textmate"
2 if test $argv
3 set dir (rdir $argv)
4 if test $dir
5 mate $dir
6 else
7 echo "Cannot find any project named '$argv'"
8 end
9 else
10 echo "Usage: rmate <project>"
11 end
12end
toggle raw diff