Search code examples
ruby-on-railsshellzshzeus

How to use an alias or function in zsh to check for a socket and run the appropriate command?


I have an interesting problem when using Zeus with Rails. My shell script writing is lacking to say the least.

Ok, so zeus boots a rails app in under a second and makes tests etc. much faster. However, you must append zeus before any rails command. Example, zeus generate controller or zeus rake db:migrate. I would rather keep the regular rails commands while running zeus. Example, rails generate controller or rake db:migrate.

I have these 3 commands aliased

alias rails='zeus'

alias rspec='zeus rspec'

alias rake='zeus rake'

However, if zeus is not running, I get this error

error: Can't connect to master. Run zeus start first.

So the problem I'm trying to solve is I would like to use the same rails commands whether zeus is running or not

Now when I run zeus start it seems that zeus.sock is present. So I guess I could check for the presence of zeus.sock in a function and then set up the alias accordingly. Im just not sure the best way to do this. I know that -S is true if file exists and is a socket. something like

if [ -S zeus.sock ]; then 
  # not sure where to go from here

Anybody have a suggestion on the best way to do this?

thanks in advance


Solution

  • You can use a function, perhaps like this:

    zrail() {
        if [ -S zeus.sock ]; then
            zeus $*
        else
            rails $*
        fi
    }
    

    Then you call it like:

    zrail generate controller