Shortcuts of bashrc
Intro
ご存知の人も多いだろうが、MacではHOME directoryに.vimrcと同じように.bashrcがある。 この.bashrcは.bash_profileを参照して...というのは Vim8.0へのupdateの記事 で説明した通りだ。
Picture
さてこの.bashrcを編集すると何が嬉しいかだ。 結論から言うとコマンドのショートカットが作れる。
Setting
先に公開すると、2019-04-09 現在の私の.bashrcはこうなっている。ちなみにVimでは "* yyでClip boardにcopyできる。
export PATH="/usr/local/bin:$PATH"
alias be='bundle exec'
alias re='exec $SHELL -l'
alias o='open'
alias sl='ls'
alias p='git push origin master'
alias a='git add .'
alias cmt='git commit'
alias s='git status'
alias pull='git pull origin master'
前半が環境構築と通常コマンド
後半がGitのコマンドだ。
一行目は環境構築なので省略
二行目から解説していく。
template
形は
alias ( short cut のこと )
自分好みのコマンド名
= ' default command '
になる。
なおvimscriptだからか = とコマンドの間は開けられない。
Explain
alias be='bundle exec'
=> rails s など起動の前に使うので短縮
alias re='exec $SHELL -l'
=> .bashrcを書き換えた後にTerminalを再起動するのは面倒。これで済む。
alias o='open'
=> 何を使うにしろ index.htmlをopenするのは飽きるほど打つことになるので o index.htmlで開いている。
alias sl='ls'
=> 鉄道は走らなくていい、素早く確認できればいいんだ。
alias p='git push origin master' alias a='git add .' alias cmt='git commit' alias s='git status' alias pull='git pull origin master' => お馴染みのgit コマンドたち。飽きるほど打つのに毎回毎回丁寧に打つのは無駄だと感じた。
alias cd=cdls
=> 後述。
conclude
以上が私が登録している.bashrcのaliasだ。
皆さんもお勧めがあったらTwitterとかで教えてくれると嬉しい。
Add
HOMEに.bash_profile がない場合は作成して source ~/.bashrc を追加することで.bashrcの読み込みをさせる必要がある。
参考 https://joppot.info/2013/12/06/72
Add2
.bash_profile のshort cutsだが、
cdのコマンドを打った後にlsもやってくれるようにするハックがあった。
function cdls() { \cd "$@" && ls }
https://joppot.info/2013/12/13/224