zsh 설치 및 설정

[2020.04.26] 우분투 20.04 Desktop 에서 테스트 완료


zsh쉘

설치

sudo apt install zsh

 

기본쉘을 zsh로 변경

# zsh의 위치 파악
which zsh
/usr/bin/zsh

# 쉘 변경
chsh -s /usr/bin/zsh

위 두 명령을 한 번에 처리하기

chsh -s \\`which zsh\\`

설치 후 터미널 재실행 - 만약 안되면 로그아웃 후 다시 접속해야 함.

재접속 후 뭔가 물어보는데 0(숫자 영)을 눌러 답했다.

oh my zsh

설치

설치 전 git, curl 이 필요하므로 설치가 되어 있지 않다면 설치하자.

sudo apt install git curl

oh-my-zsh 저장소에 에 있는 install 방법 중 curl 을 이용해 설치

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

설치 직후 Do you want to change your default shell to zsh? [Y/n] 라고 물어보면 y 를 입력해 기본 쉘로 사용한다고 설정하자.

업그레이드

upgrade_oh_my_zsh

설정

sudo vi ~/.zshrc

테마 변경

ZSH_THEME="agnoster"

테마에 필요한 폰트 설치

sudo apt install fonts-powerline

멀티라인으로 변경하기

프롬프트를 1줄이 아닌 2줄로 보기

먼저 agnoster 테마의 설정파일을 연다.

vi ~/.oh-my-zsh/themes/agnoster.zsh-theme

설정파일 제일 하단에 ## Main prompt 라는 부분이 있는데 그 위에 아래 내용을 붙여 넣는다.

prompt_newline() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR
%{%k%F{blue}%}$SEGMENT_SEPARATOR"
  else
    echo -n "%{%k%}"
  fi

  echo -n "%{%f%}"
  CURRENT_BG=''
}

마지막으로 build_prompt() 함수 안 prompt_end 위에 prompt_newline 을 입력해준다.

build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
  prompt_context
  prompt_dir
  prompt_git
  prompt_hg
  prompt_newline
  prompt_end
}

기타 플러그인 설치

zsh-syntax-highlighting

cd ~/.oh-my-zsh/plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

# .zshrc의 plugins 부분에 추가
vi ~/.zshrc

plugins=(git ... zsh-syntax-highlighting)

zsh-autosuggestions

cd ~/.oh-my-zsh/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions.git
echo "source ${(q-)PWD}/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

# .zshrc의 plugins 부분에 추가
vi ~/.zshrc

plugins=(git ... zsh-autosuggestions)

alias-tips

cd ~/.oh-my-zsh/plugins
git clone https://github.com/djui/alias-tips.git

#######################################################################
# .zshrc의 plugins 부분에 추가 그리고 파일 제일 하단에 화면에 Alias tip 구문 추가
#######################################################################
vi ~/.zshrc

plugins=(git ... alias-tips)
...
export ZSH_PLUGINS_ALIAS_TIPS_TEXT="Alias tip: "

설치 후 _alias_tips__preexec:34: command not found: python 이라는 오류를 만날 수 있다.

이 때 sudo ln -s /usr/bin/python3.8 /usr/bin/python 명령어로 python3.8을 링크시키면 해결된다.

+ Recent posts