6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macで.bashrcファイルを作成する

Posted at

Macのデフォルトって**.bashrc**ファイルってデフォルトで無いんすね...
普段、仮想環境に入ってばっかりだから、Macにもあるものだと思い込んでいた。

デフォルトで無ければ、作成すれば良いということで、作る作業の一連の流れのメモを取っておく。

これの何が便利かと言うとエイリアスとか設定できるので、作業時間が短縮するのです。(チリツモってやつです。)

.bashrcファイルを探す

  1. ホームディレクトリに移動(元からいれば別にOK)
  2. ファイルを検索します
# ホームディレクトリに移動する
$ cd ~

# bash系のファイルを探す
$ ls -la | grep 'bash'
-rw-------   1 hoge  staff   8768  9  2 18:26 .bash_history
-rw-r--r--   1 hoge  staff    243  8 30 19:05 .bash_profile
drwx------  44 hoge  staff   1408  8 28 12:26 .bash_sessions

デフォルトだとMacにはやはり無いですね。

.bashrcファイルを作成する

$ touch .bashrc

.bashrcファイルを編集してエイリアスを設定

vimを使用している人はvimで。通常の人はviコマンドで編集します。

適当に自分で設定したい項目を追記します。僕はよくgitコマンドを使用するので、gitコマンドをエイリアスに設定します。

エイリアスの設定方法は以下。
alias {設定したいコマンド名}='実際のコマンド'
※「=」の間にスペースを含むとエラーになるので注意

$ vi .bashrc

###############
# エイリアス設定
###############

# git関連
alias gsl='git stash list'
alias gsa='git stash apply'
alias gss='git stash save'
alias gpld='git pull origin develop'
alias gsd='git stash drop'
alias gr='git grep'

# その他
alias la='ls -la'

.bashrcファイルの変更を反映する

実際に.bashrcファイルを作成しただけでは読み込んでくれないので、.bash_profileに「.bashrc」を読み込んでくれー!!!という記述をしなければなりません。

$ vi .bashrc

# 以下を追記
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

そしたら、どちらのファイルもMac側に反映する必要があるのでsourceコマンドを使用して反映させます。

$ source .bashrc

$ source .bash_profile

終わり!!!

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?