Thursday, July 31, 2014

3 Alfred workflows to make your Rails developing experience easier

If you are developing on a Mac there is a good chance you already know Alfred. If you don't, you should really head over to Alfred's website and check it out. Basically it's an app launcher for OS X but one that can do a lot more! You can extend it's functionality with "workflows". Workflows are very powerful "macros" which let you do, well, basically just about anything. I use Alfred all the time and I keep adding and creating workflows for it regularly. In this post I want to tell you about 3 workflows which I have created which really help me in my day to day Rails programming.

The first workflow is a simple one called 'Insert pry'. I use pry for debugging my rails projects. It has it's pluses and minuses but overall I find it to be the most comfortable for me. In order to add a breakpoint in a ruby/rails for pry, you need to type "binding.pry". With this workflow, all I have to do is press CMD + ALT + P and it will automatically insert a breakpoint to the app I am currently using. Yeah, I know, it's not really life changing, but it will save you a little time throughout the day. :)


The second workflow is called "Insert DOOM". A lot of times when designing new features, the text for these features is only ready towards the end of the development process. I used to just write a few words like "this is the text" but I found out that adding a paragraph helps visualize how the page will look when it's done. So I created a workflow which inserts the first paragraph from Lorem Ipsum. This worked well for me for a while until I stumbled upon this blog post. The post suggests that by using a text like Lorem Ipsum, you are reducing the text element to a visual design element (like a shape). Sure this was better than just writing "this is the text", but I knew I could do something better. So I decided to take my workflow and change the text to the first paragraph from wikipedia about the game DOOM (best game ever). This way I had a few lines of real text and whenever somebody sees this text in a form or paragraph they read it and smile, and not just skip it. I use CMD + ALT + L to insert the text.

The last workflow is "Terminal Rails". I use ZSH for all my terminal uses. I noticed that many people have at least 4 tabs open when developing a rails project:
  1. Rails server
  2. Rails console
  3. A prompt for git commands, ssh, etc.
  4. Guard rspec
I noticed that this configuration of multiple tabs caused a 'big' waste of time when having to switch through them. That's when I decided to make this workflow. This workflow has 2 functions:

1. If you launch Alfred (usually alt + space) and start typing 'rails' you will get an option to launch this 4 tab configuration automatically. I programmed the workflow to start the rails server and console but not to start the guard (I don't like guard running when I don't need it). The 4 tabs will also have the corresponding name in their tab title.


2.After launching the 4 tabs, you will be able to switch to them from anywhere (not just while the terminal is focused). I have set the following shortcuts for this:
    • rs - Will switch to the rails server tab
    • rc - Will switch to the rails console tab
    • prompt - Will switch to the prompt tab
    • guard - Will switch to the guard tab

I use these workflows daily and they save me a little time everyday. I think the reason I like them so much is that I don't have to take my hands off the keyboard, grab the mouse, look with my eyes for the terminal, click on the tab, etc.

I encourage you to use Alfred workflows and create new ones yourself. Here are a few resources that will help get you started:
  • Alfred forums - The main forum for sharing workflows and getting tips and ideas for making new ones.

  • This github page has a nice collection of workflows.
  • How to create your first Alfred workflow.


  • Have fun!
    Eyal.



    4 comments:

    1. Someone needs to learn tmux.

      ReplyDelete
    2. Insert Doom Is just brilliant! Maybe it's time for me to check this Alfred app and write a few macros for my design process.

      ReplyDelete
      Replies
      1. I really think you should Pavel. Even though you are more into the design world I am sure you can think of a lot of stuff that you can automate with it. :)

        Delete