Commit #1 : Bash up your workspace!

It’s all started when I was assigned to develop a Rails web app with Haris as a team. He worked on the Rails side, while I’m on the HTML / CSS. It was my first time using Rails, and I barely have any experience on web development. Haris told me that there are several commands that should be executed to enable developing the web locally :

  • mysql.server start
  • rvm gemset use iceberg,
  • bundle install,
  • bundle exec rails s, and
  • bundle exec foreman start for running Redis server (on other terminal instance)

At that time, I typed all of those commands on my terminal each time I start working on the app, until I’ve made an embarrassing mistake – twice.

There was an “upload image” feature that we worked on, and I was trying to add the CSS when all image already uploaded. I ran the Rails app on my local machine, and tried to upload the an image to check whether my CSS really loads or not. The image upload process doesn’t finish after a good five minutes, which is strange – since it usually takes around 10 seconds max (local machine, duh). I cancelled the upload and tried to re-upload, only to see the same page stuck on uploading image. Baffled, I asked Haris for help.

Me (E) : Haris, can you check this for a sec? My image upload process never ends.
Haris (H) : Okay. *opens up Sidekiq on the other tab*
E : Something’s wrong?
H : These Carrierwave background processes queued instead of failed… Have you run the Redis server?
E : Redis what?
H : Redis server. bundle exec foreman start.
E : *slaps head*

After running on the same problem twice (yes, shame on me), I considered to automate these error-prone task. That’s when I remembered the cursed-yet-worked hammer, Bash. I made a “Scripts” folder on my root directory, and wrote four bash scripts that will change to the project directory and run the commands :

cd ~/path/to/project/folder;
rvm gemset use iceberg;
bundle install;
bundle exec rails s;

cd ~/path/to/project/folder;
rvm gemset iceberg;
bundle exec foreman start;

cd ~/path/to/project/folder;
rvm gemset use iceberg;

cd ~/path/to/project/folder
rvm gemset use iceberg;
bundle exec guard;

Each time I starts develop the app, I split my iTerm window to four panes and ran each script using source command, which will enable changing directories. It spawned this four beauties :

Screen Shot 2014-12-01 at 14.17.38

And with this, the forgot-redis-server issue is no more! 🙂

Today, I’m finding myself using this method on each project I worked on – including the mobile ones. Let’s say I got an iOS app with Cocoapods, I use this template script :

cd ~/path/to/project/folder
open *.xcworkspace
pod install

This will conveniently open up the project’s workspace and installing pods at the same time – which is less writing cd commands on my terminal, and a good thing for me 🙂

Lastly, I also use these scripts to open my work apps on the start of the day. I use these apps on my daily routine :

  • Skype
  • Slack
  • Harvest
  • Evernote

And I opened all of them using scripts. First, I add aliases for each app on my .zshrc to enable opening the app via iTerm :

#.zshrc
alias skype="open -a Skype"
alias slack="open -a Slack"
alias harvest="open -a Harvest"
alias evernote="open -a Evernote"

Then, I wrap them on these scripts :

source ~/.zshrc
skype
slack

view raw
chatapps.sh
hosted with ❤ by GitHub

source chatapps.sh
harvest
evernote

view raw
workapps.sh
hosted with ❤ by GitHub

I separated the chat apps from the others to open them without the rest – usually when I feel like reading shared articles on Slack during the weekend. This way, I can open up the terminal, run source workapps.sh and fill my glass of water while waiting the apps to load, right when I arrived at the office.

I know that I used fairly simple bash scripts to achieve this, and there might be (a lot of) developers who use more sophisticated scripts to set up their workspace. But if you never use scripts to automate your workspace, you can try the samples that I gave above 🙂

Thank you for reading! 🙂

UPDATE : A senior on my workplace, Pria, suggested me to use GitHub gists instead of quoted codes. It does look better – Thanks Mas Pria! 🙂

One Comment Add yours

  1. Echa Amalia says:

    Mas edo, kece banget nih blognya 😊

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s