ZSH

1. Homebrew for macOS

  • macOS에서 ZSH를 설치하기 위해 먼저 Homebrew를 설치한다. Ubuntu와 비슷하게 맥에서 패키지를 관리해주는 프로그램이다. 아래의 명령을 입력해 설치한다.
  • /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. iTerm2

1) 설치

  • macOS의 기본 터미널을 버리고 iTerm2를 사용한다. 몇 가지 편리한 기능 때문에 해당 터미널을 사용한다.
  • brew cask install iterm2

2) 테마 적용

  • solarized를 적용해 본다.
  • git clone git://github.com/altercation/solarized.git
  • cp ~/iterm2-colors-solarized/*.itermcolors ~/Library/Application\ Support/iTerm2/DynamicProfiles
  • rm -rf ~/iterm2-colors-solarized
  • iTerm2 > Preferences > Profiles > Colors > Color Presets > Import
  • solarized-dark 사용시 solarized-dark-patched 버전을 사용해야 zsh에 있는 autocompletion 등이 iTerm2 에서 보인다.
    • solarized-dark-patched는 위 repo에 없고 아래 repo에서 받을 수 있다. (schemes directory에 있음)
    • https://github.com/mbadolato/iTerm2-Color-Schemes.git

3. ZSH

1) 설치

- macOS

  • 기본적으로 맥북에 ZSH이 설치되어 있으나 Homebrew를 통해 관리하기 위해 아래 명령어로 설치한다.
  • brew install zsh

- Debian/Fedora

  • apt-get install zsh
  • yum install zsh

- 기본 Shell 변경

  • chsh -s /usr/local/bin/zsh

- 확인

  • 터미널을 닫고 새로 연다. 이후 아래 명령어를 통해 Shell 이 바뀌었는지 확인한다.
  • echo $SHELL
  • zsh --version

4. Oh My Zsh

  • ZSH에 테마 등을 다양한 기능을 적용하기 위한 Framework
  • curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

5. 테마 적용하기

6. 폰트 적용하기

oh my zsh를 통해 적용하는 일부 테마는 특정 폰트를 요구한다. (ex. Ubuntu Mono derivative Powerline)

  • git clone https://github.com/powerline/fonts.git --depth=1
  • ./install.sh를 실행하여 폰트를 설치한 후
  • clone 받은 폴더는 삭제한다.
  • iTerm2의 Preferences > Profiles > Text > Change Font에서 폰트를 바꾼다. (고정폭 > Ubuntu Mono ... )

7. Oh My Zsh Plugins

  • zsh-syntax-highlighting
    • git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    • Activate the plugin in~/.zshrc
      • plugins=( [plugins...] zsh-syntax-highlighting)
  • zsh-autosuggestions
    • git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
    • 만약 테마를 solarized-dark-pached를 하지 았았다면 vim 사용 시 zsh-autosuggestions이 안된다. 따라서 아래 instruction을 따른다.
      • If the auto suggestions do not appear to show, it could be a problem with your color scheme. Under "iTerm -> Preferences -> Colors tab", check the value of Black Bright, that is the color your auto suggestions will have. It will be displayed on top of the Background color, so if there is not enough contrast between the two, you won't see the suggestions, even if they're actually there.. For Solarized Dark I changed the value of Black Bright to "586e75".

8. Further Tweaking

  • Shorter Prompt Style
    • By default, your prompt will now show “user@hostname” in the prompt. This will make your prompt rather bloated. Optionally set DEFAULT_USER in ~/.zshrc to your regular username (these must match) to hide the “user@hostname” info when you’re logged in as yourself on your local machine.
  • Word Jumping in iTerm2
    • iTerm2 > Preferences > Profiles > Keys > + click
      • option + ->, Send Escape Sequence, f
      • option + <-, Send Escape Sequence, b

9. ZSH 관련 설정 파일

1) session based

~/.zshenv
~/.zprofile
~/.zshrc
~/.zlogin

2) system wide

/etc/zsh/.zshenv
/etc/zsh/.zprofile
/etc/zsh/.zshrc
/etc/zsh/.zlogin

3) How to manage system-wide configuration files

/etc/profile.d에 필요한 shell scripts를 만든 후/etc/zsh/zprofile에서 아래와 같이 파일을 불러온다.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

ex) spark.sh
export SPARK_HOME=/opt/spark

results matching ""

    No results matching ""