LoginSignup
2
5

More than 5 years have passed since last update.

zsh/bashのカスタマイズ

Last updated at Posted at 2017-01-08

zsh

zshをデフォルトで使用

ログインシェルの変更
chsh -s /bin/zsh
~/.zshrc(パスの変更)
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
~/.zshrc
LANG=ja_JP.UTF-8

# 最新のディレクトリのみ表示
PS1="%1~ %(!.#.$) "

# ヒストリの設定
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000

# cd した先のディレクトリをディレクトリスタック(履歴)に追加する
# `cd +<Tab>` でディレクトリの履歴(新しい順)が表示され、そこに移動できる
setopt AUTO_PUSHD

"~/.zshrc" 50L, 1110C

DIRSTACKSIZE=100

autoload -Uz compinit && compinit

zstyle ':completion:*' menu select
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# zstyle ':completion:*:descriptions' format '%BCompleting%b %U%d%u'

# エイリアス設定
alias ls='ls -F'
alias la='ls -a'
alias ll='ls -l'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias mkdir='mkdir -p'

# ディレクトリ移動
alias ..='cd ../'
alias ...='cd ../..'
alias ....='cd ../../..'

# 関数
# 差分表示
function diff(){
        git diff $1 --name-only
}

# 差分のみでzipをつくる
function zip(){
        git diff $1 --name-only | xargs -I {} zip $1.zip {} -x .DS_Store
}

oh-my-zsh
https://github.com/robbyrussell/oh-my-zsh

bash

~/.bash_profile:最初のログイン時に読み込まれる
~/.bashrc:ターミナル・エミュレータのウィンドウを開くたびに読み込まれる

~/.bash_profile
export PATH="$PATH:$HOME/bin"

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi
~/.bashrc
LANG=ja_JP.UTF-8
PS1='\W \$ '
export LESS='--no-init'

set -o ignoreeof

# コマンド履歴設定
shopt -s histappend
HISTSIZE=1000000
HISTFILESIZE=1000000

※ aliasや通常の変数は引き継がれないため、~/.bashrcに記述する必要がある

※ 例えばaliasに登録したlsを一時的に無効に(本来のlsを実行)する場合はcommand ls もしくは \ls

参考
新しいLinuxの教科書

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

LANG=ja_JP.UTF-8

# 最新のディレクトリのみ表示
PS1="%1~ %(!.#.$) "

# ヒストリの設定
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000

# cd した先のディレクトリをディレクトリスタック(履歴)に追加する
# `cd +<Tab>` でディレクトリの履歴(新しい順)が表示され、そこに移動できる
setopt AUTO_PUSHD

# pushd したとき、ディレクトリがすでにスタックに含まれていればスタックに追加しない
setopt pushd_ignore_dups

DIRSTACKSIZE=100

autoload -Uz compinit && compinit

zstyle ':completion:*' menu select
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# zstyle ':completion:*:descriptions' format '%BCompleting%b %U%d%u'

# エイリアス設定
alias ls='ls -F'
alias la='ls -a'
alias ll='ls -l'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias mkdir='mkdir -p'

# ディレクトリ移動
alias ..='cd ../'
alias ...='cd ../..'
alias ....='cd ../../..'

# 関数
# 差分表示
function diff(){
        git diff $1 --name-only
}

# 差分のみでzipをつくる
function gzip(){
        git diff $1 --name-only | xargs -I {} zip $1.zip {} -x .DS_Store
}


export PATH="/usr/local/sbin:$PATH"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

参考
初めて Mac で zsh を使う人のためのチュートリアル
【図解】ゼロから始めるモダンなコマンドライン環境作り #iTerm2 #tmux #zsh

2
5
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
2
5