Recent News

Less work, more be-ing with quick shell aliasing

This weekend, after working an endless 5 hour work week, I decided that I want to implement new ways for me to continue to be even lazier than I already am…

After laboriously lifting my heavy 4” long fingers to ssh into another server that I couldn’t remember the IP address for, I started to think there has to be a better way.

Why am I always repeatedly type long lines of ssh logins, rake tasks, etc. into the command line? I’m always trying to stay DRY in my application code, and it’s got me thinking, how can I sort of stay “DRY” at the command line and limit the amount of work that I do?

Why don’t I create time saving aliases more often?

One big reason that I don’t create time saving aliases more often is because it’s not brain-dead-easy enough for me to edit my .bash_profile… so, I created an alias to quickly edit my .bash_profile:

# 'be' (for "bash edit")
  alias be='mate ~/.bash_profile'
The really sweet version that re-sources your .bash_profile after you save your changes is:
alias be='mate -w ~/.bash_profile;source ~/.bash_profile'

Then, I decided to take a look at where I could reduce repetitive tasks, so I executed the history command to see what are some of the longer commands that I’ve written repetitively.

~ $ history
   10  ssh deploy@myserver.railsmachina.com
   13  cd Projects2/
   55  rake db:migrate
   57  rake db:migrate RAILS_ENV=test
   88  rake ultrasphinx:bootstrap

I see that I’m typing a lot of long rake tasks like rake db:migrate, rake ultrasphinx:bootstrap, cd Projects/post_it, cd Projects/my_project

So, I’m going to add those…
alias rdb='rake db:migrate'
alias rub='rake ultrasphinx:bootstrap'
alias my_project='cd Projects/my_project/trunk/'
I don’t want to go crazy in one day and add EVERYTHING, I’d rather fine tune this over time and make the process of adding and editing my bash_profile easier… So, by just adding the be alias, I now have an easier way to create shortcuts and it makes me a much happier programmer:
alias be='mate ~/.bash_profile'

We discussed the possibility of writing a function (let’s call it balias) that could automatically add an alias to your bash_profile (e.g. balias myserver "ssh live@8.23.456.78"). My only hesitation with doing that is it could make your .bash_profile a disorganized mess… But, it would be very nice to just add new aliases via command line.

The other challenge is how do you remember all these shortcuts? Type alias in your command line to remember what aliases you have added.
~ $ alias
alias be='mate -w ~/.bash_profile;source ~/.bash_profile'
alias ett='mate app config lib db public test vendor/plugins &'
alias gd='git diff | mate'
alias app_live_1='ssh live@8.22.345.67'
alias app_live_2='ssh live@8.22.345.99'
alias app_live_db='ssh live@8.22.345.222'
alias app_sandbox='ssh sandbox@8.22.43.243'
alias app_staging='ssh staging@8.22.43.244'
alias rdb='rake db:migrate'
alias rdbt='rake db:migrate RAILS_ENV=test'
alias td='mate ~/Documents/todo.txt'
Footnotes:
  • See other people’s .bash_profiles here: http://dotfiles.org/
  • You can also edit your .ssh/config, but I find it just as good to put them in the .bash_profile.
  • You can set up autocomplete for ssh as well – using this Life changing shell function, I’m probably missing something about setting up .ssh/config, but right now, it’s not working well for me since all my logins are always ssh username@8.34.56.123 and not simply ssh domain_name.


Comments are closed

cementhorses.com

Categories

Cement Horses Pics

Archives