Your SlideShare is downloading. ×
0
ru sh <ul><li>a shell that will  yield  to you </li></ul>
http://flickr.com/photos/exquisitur/2551255999/
What is ru sh ? <ul><li>Unix shell with ruby  syntax and idioms </li></ul><ul><li>by Adam Wiggins (Heroku) </li></ul>
Install and Run $ sudo gem install rush $ rush rush> home=> localhost:/Users/schlueter/
No  Working Directory $ home => localhost:/Users/schlueter $ root=> localhost://// $  rushmate  =  home[ &quot;mydev/githu...
But ls Still Works $ home[ &quot;mydev/github/rushmate/&quot; ].ls /Users/schlueter/mydev/github/rushmate/ coverage/ lib/ ...
Make a Variable $  rushmate  =  home[ &quot;mydev/github/rushmate/&quot; ]
File Manipulation http://flickr.com/photos/takashi/18862634/
Rename # assign a file to a variable $ file  =  rushmate[ 'app/models/rushmate.rb' ] $ file.rename  'russian_mate.rb'
Duplicate a File $ file  =  rushmate[ 'README' ] $ file.duplicate  'README.markdown'
Copy Different Directory $ file  =  rushmate[ 'README' ] $ file.copy_to other_project[ 'README' ]
Move $ file  =  rushmate[ 'README' ] $ file.move_to home[ 'Desktop/' ]
Write a File $ file  =  rushmate[ 'README' ] $ file.write  &quot;You Read Me&quot;
Read a File $ rushmate[ &quot;README&quot; ].contents You Read Me
File Globbing
Basic Globbing $  rushmate[ &quot;**/*.rb&quot; ] .../mydev/github/rushmate/lib/rushmate.rb.../mydev/github/rushmate/lib/r...
Glob into an Editor $  rushmate[ &quot;**/*.rb&quot; ].vi $  rushmate[ &quot;**/*.rb&quot; ].mate
Operate on Results $ rails_proj[ '**/*.rhtml' ].each { | f |   f.rename f.name.gsub( / . rhtml/ ,  '.html.erb' ) }
Results Are an Array $ rushmate[ &quot;**/*.rb&quot; ].reject {| f | f.name.match( /test.rb/ )} Go Nuts! $ rails_project[ ...
embed http://flickr.com/photos/liamngls/413522957/ Rush :: EmbeddableShell . new .execute_in_shell  do   #anything in here...
Sake Quick Index of RDoc task  'rdoc:local'  =>  'rush'   do   shell  =   Rush :: EmbeddableShell . new   shell.execute_in...
sake rdoc:local
 
Refactoring http://flickr.com/photos/tonyjcase/2262229518/
Search $ work[ &quot;**/*.rb&quot; ].search( /  Rushmate  / ) .../test/user_input_test.rb  => assert_equal(&quot;foo&quo...
and Replace <ul><li>$ rushmate[ &quot;**/*.rb&quot; ].replace_contents! </li></ul><ul><ul><li>( /  Rushmate  / ,  &quot;...
Regex is your friend $ project_files.replace_contents!  ( /User.authenticate (s *(.*), s *(.*) ) / ,  'User.authenticate( ...
Processes <ul><li>ff.alive? </li></ul><ul><li>ff.mem </li></ul><ul><li>ff.pid </li></ul><ul><li>ff.cpu </li></ul><ul><li>f...
Real World Rush :: EmbeddableShell . new .execute_in_shell  do end ff_processes  =  processes. filter ( :cmdline  =>  /fir...
Permissions $ file.access  =   { :user_can  =>  :read_and_write ,    :group_and_other_can  =>  :read  } $ file.access[ :us...
Use BASH if you must $ rushmate.bash  &quot;rm -rf .&quot; # D'oh!
Shell Locally Act Globally
Remote $  remote  =   Rush :: Box . new ( 'user@server.com' ) $  remote[ &quot;/u/app/current/REVISION&quot; ].contents =>...
Starts a Mongrel on Remote Server Use in production with caution
Customize # setup variables to common directories rushmate  =  home[ &quot;mydev/github/rushmate/&quot; ] # setup variable...
Cheap Backup def   cheap_backup (directory)   unless  directory.dir?   puts  &quot;cheap backup only works on dirs&quot;  ...
Extend # allows you to run  # directory.coverage def   coverage   self .rake( &quot;coverage&quot; ) end ~/.rush/commands.rb
Another Command def   ruby_files   self [ &quot;**/*.rb&quot; ] end $ rushmate.ruby_files .../mydev/github/rushmate/lib/ru...
 
TextMate Rushmate :: Command . new  {   # find ruby files with the current word in textmate   found_files  =  project_dire...
The Take Away
Questions ?
Thank You <ul><li>schlueter @gmail.com </li></ul>http://www.simpl try.com
Upcoming SlideShare
Loading in...5
×

Rush, a shell that will yield to you

1,642

Published on

Rush is a shell with ruby syntax and idioms. This presentation goes over how to use it and embed it in other applications.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,642
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
28
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Rush, a shell that will yield to you"

  1. 1. ru sh <ul><li>a shell that will yield to you </li></ul>
  2. 2. http://flickr.com/photos/exquisitur/2551255999/
  3. 3. What is ru sh ? <ul><li>Unix shell with ruby syntax and idioms </li></ul><ul><li>by Adam Wiggins (Heroku) </li></ul>
  4. 4. Install and Run $ sudo gem install rush $ rush rush> home=> localhost:/Users/schlueter/
  5. 5. No Working Directory $ home => localhost:/Users/schlueter $ root=> localhost://// $ rushmate = home[ &quot;mydev/github/rushmate/&quot; ] => localhost:/Users/schlueter/mydev/github/rushmate/
  6. 6. But ls Still Works $ home[ &quot;mydev/github/rushmate/&quot; ].ls /Users/schlueter/mydev/github/rushmate/ coverage/ lib/ test/ History.txt MIT-LICENSE Manifest.txt
  7. 7. Make a Variable $ rushmate = home[ &quot;mydev/github/rushmate/&quot; ]
  8. 8. File Manipulation http://flickr.com/photos/takashi/18862634/
  9. 9. Rename # assign a file to a variable $ file = rushmate[ 'app/models/rushmate.rb' ] $ file.rename 'russian_mate.rb'
  10. 10. Duplicate a File $ file = rushmate[ 'README' ] $ file.duplicate 'README.markdown'
  11. 11. Copy Different Directory $ file = rushmate[ 'README' ] $ file.copy_to other_project[ 'README' ]
  12. 12. Move $ file = rushmate[ 'README' ] $ file.move_to home[ 'Desktop/' ]
  13. 13. Write a File $ file = rushmate[ 'README' ] $ file.write &quot;You Read Me&quot;
  14. 14. Read a File $ rushmate[ &quot;README&quot; ].contents You Read Me
  15. 15. File Globbing
  16. 16. Basic Globbing $ rushmate[ &quot;**/*.rb&quot; ] .../mydev/github/rushmate/lib/rushmate.rb.../mydev/github/rushmate/lib/rushmate/command.rb.../mydev/github/rushmate/lib/rushmate/exit.rb ... => 9 x Rush :: File
  17. 17. Glob into an Editor $ rushmate[ &quot;**/*.rb&quot; ].vi $ rushmate[ &quot;**/*.rb&quot; ].mate
  18. 18. Operate on Results $ rails_proj[ '**/*.rhtml' ].each { | f | f.rename f.name.gsub( / . rhtml/ , '.html.erb' ) }
  19. 19. Results Are an Array $ rushmate[ &quot;**/*.rb&quot; ].reject {| f | f.name.match( /test.rb/ )} Go Nuts! $ rails_project[ &quot;**/*.rhtml&quot; ] + rails_project[ &quot;**/*.html.erb&quot; ]
  20. 20. embed http://flickr.com/photos/liamngls/413522957/ Rush :: EmbeddableShell . new .execute_in_shell do #anything in here delegates to rush end
  21. 21. Sake Quick Index of RDoc task 'rdoc:local' => 'rush' do shell = Rush :: EmbeddableShell . new shell.execute_in_shell do end end ruby = root[ &quot;/Library/Ruby/Gems/1.8/&quot; ] indexes = ruby[ &quot;doc/*/rdoc/index.html&quot; ] hrefs = indexes.collect { | f | path = f.full_path text = path.match( /doc / (.*) / rdoc/ )[ 1 ] &quot;<a href= &quot; #{path} &quot; >#{text}</a>&quot; } home[ &quot;rdoc.html&quot; ].write hrefs.join( &quot;<br />&quot; ) home.bash( &quot;open rdoc.html&quot; )
  22. 22. sake rdoc:local
  23. 24. Refactoring http://flickr.com/photos/tonyjcase/2262229518/
  24. 25. Search $ work[ &quot;**/*.rb&quot; ].search( /  Rushmate  / ) .../test/user_input_test.rb => assert_equal(&quot;foo&quot;, Rushmate ::.../lib/rushmate/command.rb => module Rushmate .../lib/rushmate/exit.rb => module Rushmate ...7 matching files with 25 matching lines $ work[ &quot;**/*.rb&quot; ].search( /  Rushmate  / ).mate
  25. 26. and Replace <ul><li>$ rushmate[ &quot;**/*.rb&quot; ].replace_contents! </li></ul><ul><ul><li>( /  Rushmate  / , &quot;RussianMate&quot; ) </li></ul></ul>.../lib/rushmate.rb.../lib/rushmate/command.rb.../lib/rushmate/exit.rb => 9 x Rush :: File
  26. 27. Regex is your friend $ project_files.replace_contents! ( /User.authenticate (s *(.*), s *(.*) ) / , 'User.authenticate( 2, 1)' ) User .authenticate(user, password) User .authenticate(password, user)
  27. 28. Processes <ul><li>ff.alive? </li></ul><ul><li>ff.mem </li></ul><ul><li>ff.pid </li></ul><ul><li>ff.cpu </li></ul><ul><li>ff.kill </li></ul>$ ff = processes.filter( :cmdline => /firefox/ ).first
  28. 29. Real World Rush :: EmbeddableShell . new .execute_in_shell do end ff_processes = processes. filter ( :cmdline => /firefox/ ) if ff = ff_processes.select{| p | p.mem > 400000 }.first ff_cmdline = ff.cmdline ff.kill home.bash ff_cmdline, :background => true end
  29. 30. Permissions $ file.access = { :user_can => :read_and_write , :group_and_other_can => :read } $ file.access[ :user_can_read ] => true
  30. 31. Use BASH if you must $ rushmate.bash &quot;rm -rf .&quot; # D'oh!
  31. 32. Shell Locally Act Globally
  32. 33. Remote $ remote = Rush :: Box . new ( 'user@server.com' ) $ remote[ &quot;/u/app/current/REVISION&quot; ].contents => 160
  33. 34. Starts a Mongrel on Remote Server Use in production with caution
  34. 35. Customize # setup variables to common directories rushmate = home[ &quot;mydev/github/rushmate/&quot; ] # setup variables to common servers qa = Rush :: Box . new ( 'user@qa.local' ) ~/.rush/evn.rb
  35. 36. Cheap Backup def cheap_backup (directory) unless directory.dir? puts &quot;cheap backup only works on dirs&quot; return end backup_path = directory.path + &quot;/&quot; + directory.name + &quot;.bak&quot; if self [backup_path].exists? puts &quot;backup already exists&quot; else directory.duplicate(directory.name + &quot;.bak&quot; ) end end
  36. 37. Extend # allows you to run # directory.coverage def coverage self .rake( &quot;coverage&quot; ) end ~/.rush/commands.rb
  37. 38. Another Command def ruby_files self [ &quot;**/*.rb&quot; ] end $ rushmate.ruby_files .../mydev/github/rushmate/lib/rushmate.rb.../mydev/github/rushmate/lib/rushmate/command.rb.../mydev/github/rushmate/lib/rushmate/exit.rb ... => 9 x Rush::File
  38. 40. TextMate Rushmate :: Command . new { # find ruby files with the current word in textmate found_files = project_directory[ &quot;**/#{current_word.downcase}.rb&quot; ] if found_files.size == 1 found_files.mate else menu_files = found_files.collect { | f | f.full_path.gsub(project_directory.full_path, &quot;&quot; ) } project_directory[user_input.quick_menu_from_array(menu_files)].mate end }
  39. 41. The Take Away
  40. 42. Questions ?
  41. 43. Thank You <ul><li>schlueter @gmail.com </li></ul>http://www.simpl try.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×