본문 바로가기

os/mac os

Oh My Zsh 설치 & Plugins

macOS Catalina부터 기본 Shell로 zsh를 사용합니다.

개인적으로 bash만 사용해서 zsh가 어색하기도 하지만 한번 zsh에 적응해보고자 합니다.

Installation

curl을 이용하여 Oh My Zsh를 설치합니다. 

 

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

 

별 문제없이 작동이 되면 다음 Theme로 이동하시면 됩니다.

 

 

만약, 아래처럼 복잡한 메시지가 뜨는 경우에만 아래 해결책을 사용하세요.

아래 문제는 해당 directory의 ower가 현재 user와 다른 경우에 발생합니다.

맥에 2개의 계정이 있는데 서로 다른 계정을 사용하면서 생긴 문제입니다.

 

[oh-my-zsh] Insecure completion-dependent directories detected:
drwxr-xr-x  3 goaxmin  admin   96 Feb 26 21:41 /usr/local/share/zsh
drwxr-xr-x  4 goaxmin  admin  128 Feb 26 21:44 /usr/local/share/zsh/site-functions
lrwxr-xr-x  1 goaxmin  admin   39 Feb 26 21:44 /usr/local/share/zsh/site-functions/_brew -> ../../../Homebrew/completions/zsh/_brew
lrwxr-xr-x  1 goaxmin  admin   44 Feb 26 21:44 /usr/local/share/zsh/site-functions/_brew_cask -> ../../../Homebrew/completions/zsh/_brew_cask

[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.

[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh]     compaudit | xargs chmod g-w,o-w

[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.

 

권한을 변경하거나 마지막 설명처럼 ZSH_DISABLE_COMPFIX="true" 로 설정하면 됩니다.

마지막 문장이 중요한데, 반드시 .zshrc의 oh-my-zsh를 source하기 전에 해야 합니다.

라인 번호는 다를 수 있으니 검색을 이용해서 적당한 라인에 해당 값을 입력합니다.

 

vi ~/.zshrc

 

 66 # Which plugins would you like to load?
 67 # Standard plugins can be found in ~/.oh-my-zsh/plugins/*
 68 # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
 69 # Example format: plugins=(rails git textmate ruby lighthouse)
 70 # Add wisely, as too many plugins slow down shell startup.
 71 plugins=(git)
 72 
 73 ZSH_DISABLE_COMPFIX="true"
 74 
 75 source $ZSH/oh-my-zsh.sh

 

Themes

기본 테마는 robbyrussell로 설정되어 있으며, 유명한(?) agnoster 테마로 변경합니다.

 

  7 # Set name of the theme to load --- if set to "random", it will
  8 # load a random theme each time oh-my-zsh is loaded, in which case,
  9 # to know which specific one was loaded, run: echo $RANDOM_THEME
 10 # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
 11 ZSH_THEME="agnoster"

 

폰트가 설치되지 않아 글자가 깨져보입니다.

 

 

Powerline 폰트를 설치하면 정상적으로 보입니다.

저는 Menlo 폰트를 사용하고 있으므로 해당 github에서 소스를 받아 설치합니다.

 

ttf폰트를 선택한 후 ContextMenu Open With  Font Book을 실행한 후, 오른쪽 하단의 Install Font를 눌러 폰트를 설치합니다.

폰트가 설치된 후 Terminal의 Profiles에서 폰트를 Menlo Regular for Powerline으로 변경합니다.

 

삼각형의 픽셀이 약간 내려왔는데요. Line Spacing을 조절하여 최적의 상태를 찾아냅니다.

 

 

완벽하진 않지만 이정도로 타협을 봐야겠네요.

 

Plugins 

zsh의 꽃(?)은 plugin이므로 인기있는 Plugin 몇개를 살펴보겠습니다.

Autojump

autojump는 파일 시스템을 빠르게 탐색할 수 있습니다. brew를 이용하여 설치합니다.

 

brew install autojump

 

설치후에 .zshrc의 plugins에 autojump를 추가합니다.

 

 66 # Which plugins would you like to load?
 67 # Standard plugins can be found in ~/.oh-my-zsh/plugins/*
 68 # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
 69 # Example format: plugins=(rails git textmate ruby lighthouse)
 70 # Add wisely, as too many plugins slow down shell startup.
 71 plugins=(git autojump)

 

autojump는 jump하기 전에 반드시 한번은 cd로 탐색해야만 합니다.

여러 디렉토리를 cd로 돌아다닌 후, autojump -s로 방문한 디렉토리의 기록을 볼 수 있습니다.

 

사용법

  • foo를 포함하는 디렉토리로 점프
    • j foo
  • 현재 디렉토리의 자식 디렉토리로 점프
    • jc bar
  • Jump하지 않고 해당 디렉토리를 File Manager로 실행 (Mac Finder, Windows Explorer, GNOME Nautilus, etc.)
    • jo foo
    • jco bar

 

Auto Suggestions

터미널 입력시 History 기반 단어(?)를 추천해줍니다.

 

$ brew install zsh-autosuggestions
==> Downloading https://github.com/zsh-users/zsh-autosuggestions/archive/v0.6.4.tar.gz
==> Downloading from https://codeload.github.com/zsh-users/zsh-autosuggestions/tar.gz/v0.6.4
##O#- #                                                                       
==> Caveats
To activate the autosuggestions, add the following at the end of your .zshrc:

  source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

You will also need to force reload of your .zshrc:

  source ~/.zshrc
==> Summary
🍺  /usr/local/Cellar/zsh-autosuggestions/0.6.4: 6 files, 43.6KB, built in 5 seconds

 

설치 후에 zsh-autosuggestions.zsh를 .zshrc의 마지막에 추가해야 합니다.

 

echo "source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc

 

새 Tab에서 확인해보면 아래와 같은 단어(?) 추천을 볼 수 있습니다.

사용법

  • 전체 제안 Command를 적용하려면
    • or End
  • 단어 단위로 제안 Command를 적용하려면
    • +

Syntax Highlighting

zsh에서 해당 Command가 실행될 수 있는지 또는 에러인지 확인할 수 있습니다.

zsh-syntax-highlighting 플러그인을 설치해보겠습니다.

 

mac의 경우에는 brew를 이용할 수 있겠지만 plugin manager방식으로 설치하겠습니다.

아래 명령으로 plugins 디렉토리에 다운받습니다.

 

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

 

설치가 성공하면 해당 디렉토리에 파일이 생성됩니다.

 

$ ll ~/.oh-my-zsh/custom/plugins        
total 0
drwxr-xr-x   3 goax  staff    96B Feb 27 20:19 example
drwxr-xr-x  22 goax  staff   704B Feb 28 00:41 zsh-syntax-highlighting

 

아래 Command로 .zshrc의 마지막에 zsh-syntax-highlighting.zsh를 추가합니다.

 

echo "source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${HOME}/.zshrc

 

새 Tab에서 Command의 색상이 바뀐것을 확인하셨다면, 성공!!

 

Tip

zsh에서 git log -1 후 엔터를 쳐야 하는 경우

 

Pager로 less가 설정되어 있으므로 이를 해제합니다.

(~/.oh-my-zsh/lib/misc.zsh에 LESS 가 설정되어 있음)

 

# ~/.zshrc의 마지막에 아래 내용을 추가합니다.
unset LESS;

Bash 를 쓸까?

Catalina에는 bash가 설치되어 있습니다. 하지만 버전은 3.2입니다.

 

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
Copyright (C) 2007 Free Software Foundation, Inc.

 

아래 명령으로 기본 Shell을 bash로 변경할 수 있습니다.

 

$ chsh -s /bin/bash

 

새 Tab으로 새로운 Shell을 생성하면 아래와 같은 메시지가 표시됩니다.

 

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

 

이 메시지를 없애기 위해서는 ~/.bash_profile에 아래 변수를 추가합니다.

 

export BASH_SILENCE_DEPRECATION_WARNING=1

 

어찌되었건 bash를 잠시 접어두고 zsh에 적응해봐야겠네요.

 

'os > mac os' 카테고리의 다른 글

Terminal Hostname 변경  (0) 2020.02.27
macOS Terminal Theme (Smyck)  (0) 2020.02.27
Homebrew 설치  (0) 2020.02.27
한영 단축키 Shift + Space로 변경  (0) 2020.02.27