iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 19
1
Modern Web

Ruby礦工的Rails地圖系列 第 19

How to set command line alias on mac

今天要講的跟rails本身沒有直接關係
但是卻會扎實地影響到開發速度
身為一個軟體工程師
以下的指令一定是每天在使用

git push
git pull
rake db:migrate
rake g migration
...

雖然也不算長
但是常常要打,也是會花一些時間
如果能夠讓這些指令縮短
是不是日常工作上,就能省下更多時間呢?
今天就來一步一步地說明要怎麼做

  1. 開Terminal
  2. 先到根目錄
cd ~/ 

3.創建一個.bash_profile檔,用來記錄快捷

touch .bash_profile

4.進去編輯,這邊的範例是使用vim為預設的編輯器

vim .bash_profile

5.輸入想要的預設,比方說:

alias gs="git status"

在vim編輯需要特別說明一下
編輯需要先輸入i才會進入編輯文字,最下方有一行-- INSERT --
編輯完成後要按左上角的[ESC]脫離編輯模式
接著按[shift + :]進入指令模式
然後在下方指令列輸入wq,分別是寫入且離開
這樣就可以完成編輯囉
6.重新載入.bash_profile

. .bash_profile

7.最後只要把Terminal關掉重新啟動,剛剛的設定就可以生效囉!
這個時候你只要輸入gs
對Terminal來說就像是輸入git status一樣唷

我的建議如下:

alias gs = "git status"
alias gb = "git branch"
alias gps = "git push"
alias gpl = "git pull"
alias rc = "rails c"
alias rs = "rails s"
alias b = "bundle"
alias rd = "rake db:migrate"

供大家做參考
是不是很神奇呀,祝福大家開發速度都能加快囉 :)


上一篇
rails mailer preview skill
下一篇
路由 routes
系列文
Ruby礦工的Rails地圖30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言