터미널에서 zsh 와 oh-my-zsh 사용하기

zsh 와 zsh-completions 설치하기

mac에서 설치

brew install zsh zsh-completions

ubuntu에서 설치

sudo apt-get install zsh
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/shells:/zsh-users:/zsh-completions/xUbuntu_18.10/ /' > /etc/apt/sources.list.d/shells:zsh-users:zsh-completions.list"
sudo apt-get update
sudo apt-get install zsh-completions

oh-my-zsh 설치

[mac / ubuntu 공통]

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

테마 변경하기

oh-my-zsh의 기본 테마인 robbyrussell도 깔끔하지만, 이 외에 다양한 테마가 존재한다. 테마를 바꾸는 방법은 ~/.zshrc파일의 ZSH_THEME="robbyrussell" 부분을 원하는 테마로 수정하면 된다. random으로 설정한 후 source ~/.zshrc 을 입력할때마다 새로운 테마로 새로고침 된다. 마음에 드는 테마를 확인한 후 해당 테마를 적용한다.

# ZSH_THEME="robbyrussell"
ZSH_THEME="random"

단축명령어 확인하고 활용하기

alias를 입력하면 설정된 단축 명령을 확인하고 활용한다.

-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..

~ 중 략 ~

la='ls -lAh'
ll='ls -lh'
ls='ls --color=tty'
lsa='ls -lah'
md='mkdir -p'
please=sudo
rd=rmdir
which-command=whence

zsh-syntax-highlightingzsh-autosuggestions 설치하기

[mac / ubuntu 공통]

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

# zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

플러그인을 설치하면 반드시 ~/.zshrc파일에 설정을 해야한다. 파일을 열고 plugins항목에 플러그인을 추가한다.

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

fasd 설치하기

mac에서 설치

brew install fasd

ubuntu에서 설치

sudo add-apt-repository ppa:aacebedo/fasd
sudo apt-get update
sudo apt-get install fasd

[mac / ubuntu 공통]

설치가 완료되었으면 ~/.zshrc에 plugin을 추가해 준다.

plugins=(
  ...
  ...
  fasd
)

명령어

명령어를 사용하기 위해서는 일단 디렉토리를 좀 이동하고 파일도 열어보고 해야 한다. 어느 정도 히스토리가 쌓이면 명령어를 입력해 본다.

단축키기능
z디렉토리 이동
s파일 or 디렉토리 검색

자신이 자주 사용하는 명령어를 새로 등록하여 사용할 수 있다. 예를 들어 php artisan이라는 명령을 pats으로 사용하려면 터미널에서 alias pats='php artisan'을 입력하고 alias로 전체 목록에 포함되었는지 확인한다.


fzf (퍼지 파인더) 설치하기

fzf는 강력하고 엄청나게 빠른 fuzzy finder 도구이다. 증분 검색을 통하여 원하는 파일이나 히스토리를 쉽고 빠르게 찾을 수 있게 해준다. 정확하게 원하는 값을 입력하지 않고 일부만 입력해도 실시간으로 검색 결과를 보여준다.

mac에서 설치

brew install fzf

brew 설치 후 install 명령어를 입력하면 몇 가지를 물어보는데 전부 y를 누르면 된다.

ubuntu에서 설치

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

명령어

정말 다양하게 사용할 수 있지만 여기선 가장 기본적인 기능만 살펴본다.

단축키기능
 + T하위 디렉토리 파일 검색
 + R히스토리 검색
esc + C하위 디렉토리 검색 후 이동

댓글 남기기