MLUG: [MLUG] bash shortcuts for Rails (fwd)
[MLUG] bash shortcuts for Rails (fwd)
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
This is an interesting idea from someone on our local Ruby list. He's using some bash tricks that I hadn't seen before (not that I'm an expert) like use of an "until" loop in an alias. --Mike


---------- Forwarded message ---------- Date: Wed, 11 Jul 2007 11:40:15 -0500 From: Jeremy To: EMAIL:PROTECTED Subject: [ruby.mn] Linux shortcuts for Rails


If anyone is interested, I made some Rails aliases for the Linux shell. They should work on other platforms that support Bash.

When moving around directory structures, I like single-character aliases for
common directory names.  It's usually faster than tab-autocomplete.

  r        chdir to the root of the rails project (sticky setting)
  ra      chdir to /app
  rav    chdir to /app/views
  ravl   chdir to /app/views/layouts

These commands find the root dynamically by examining parent directories.  It
will pop up through parent directories until it finds something resembling
the rails root (takes ~6 milliseconds), then descend to the desired
subdirectory.  If you use these commands outside of a rails tree, it will
attempt to use the last-known tree.  This makes it easy to chdir to /etc and
return without a pushd/popd.

These lines can just be added to the ~/.bashrc script.  Provided as-is :)

---------------------------------------
# the command below is intended to be on one line
alias r="until ([ \`pwd\` == \"/\" ] || test -e app/views/layouts); do
cd ..;done; if [ \"\$PWD\" == \"/\" ]; then cd \$lastRailsRoot; else
lastRailsRoot=\$PWD; fi"

alias ra="r; cd app;"
alias ram="r; cd app/models"
alias rav="r; cd app/views"
alias ravl="r; cd app/views/layouts"
alias rah="r; cd app/helpers"
alias rac="r; cd app/controllers"
alias rps="r; cd public/stylesheets"
alias rdm="r; cd db/migrate"
alias rpj="r; cd public/javascripts"
alias rl="r; cd lib"
alias rlg="r; cd log"
alias rc="r; cd config"
alias rd="r; cd doc"
alias rvp="r; cd vendor/plugins"
alias rt="r; cd test"
alias rtu="r; cd test/unit"
alias rtm="r; cd test/mocks"
alias rtfx="r; cd test/fixtures"
alias rtfn="r; cd test/functional"
alias rti="r; cd test/integration"
# etc, etc...

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members