본문 바로가기
개발/etc

Mac 터미널 세팅과 꾸미기

by 달사쿠 2022. 2. 1.
반응형

Intro

Mac pro를 받고 다시 터미널을 세팅하려니 어떻게 세팅했는지 새까맣게 까먹었다. 미래를 나를 위해 정리해두는 터미널 첫 세팅과 꾸미는 방법.. (다음번엔 빠르게 샤삭하자)

 


Iterm2, Homebrew, zsh 설치

Iterm2

terminal을 대체해 더 다양한 기능을 제공해주는 애플리케이션

iterm2 홈페이지에서 다운로드: https://iterm2.com/

 

iTerm2 - macOS Terminal Replacement

iTerm2 by George Nachman. Website by Matthew Freeman, George Nachman, and James A. Rosen. Website updated and optimized by HexBrain

iterm2.com

 

brew

macOS 패키지 관리자: https://brew.sh/index_ko

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

zsh, oh my zsh

bash의 확장된 유닉스 셸

# zsh install
brew install zsh

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

 


Font, Color scheme, Powerlevel10K, LSD

Nerd Font 

Nerd Fonts는 많은 수의 glyphs(icons)를 가진 대상 font를 패치한다.

구체적으로 Font Awesome, Devicons, Octicons 등 인기 'iconic fonts'에서 추가 글리프를 대거 추가했다.

 

Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher

Iconic font aggregator, collection, & patcher: 3,600+ glyph/icons, 40+ patched fonts: Hack, Source Code Pro, more. Popular glyph collections: Font Awesome, Octicons, Material Design Icons, and more

www.nerdfonts.com

#모든 Nerd font 설치
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font

한국어 readme가 있어서 첨부한다.

https://github.com/ryanoasis/nerd-fonts/blob/master/readme_ko.md

 

GitHub - ryanoasis/nerd-fonts: Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+ patched fonts: Hack, Source Code

Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+ patched fonts: Hack, Source Code Pro, more. Glyph collections: Font Awesome, Material Design Icons, Octicons, & more - GitHu...

github.com

 

Color Scheme: Gogh

https://mayccoll.github.io/Gogh/

#Gogh 설치. ALL을 입력하면 모두 설치된다.
bash -c  "$(curl -sLo- https://git.io/vQgMr)"

 

iterm2에서 테마, 폰트 세팅하는 방법

  • Preferences (터미널 + ,) > Profiles > Colors > 우측 맨 아래의 "Color Presets" 클릭 후 테마 선택
  • Preferences (터미널 + ,) > Profiles > Texts > Font 클릭 후 "Nerd Font ~" 클릭

개인적으로 테마는 "Flatland", "Molokai"가 좋았다. (이건 취향~)

 

Powerlevel10K

Powerlevel10K를 oh-my-zsh 환경에서 쉽게 세팅하는 것은 아래와 같다. (https://github.com/romkatv/powerlevel10k#oh-my-zsh)

1. repository 클론

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

2. .zshrc 파일에 아래와 같이 ZSH_THEME를 변경

ZSH_THEME="powerlevel10k/powerlevel10k"

3. 터미널에서 p10k configure 입력

 

이후엔 취향 것 iterm을 꾸미면 된다.

 

LSD

'ls' commend의 다음세대 명령어로 불린다. (이건 잘모르겠고, ls할 때 이쁘게 커스텀하고 싶으면 사용하면 된다.)

# 설치
brew install lsd

#alias 세팅
vim ~/.zshrc # 또는 vi ~/.zshrc

alias ls='lsd'
alias ll='ls -alhF'

# 적용
source ~/.zshrc

 


유용한 Plugins

처음에 Plugin은 아래와 같이 git만 세팅되어있을 것이다.

plugins=(git)

여기에 zsh-autosuggestions, syntax highlighting, autojump 플러그인을 추가할 것이다.

 

zsh-autosuggestions

전에 사용한 적이 있는 명령어를 자동완성시켜주는 플러그인

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

repo를 클론 받은 다음 아래와 같이 .zshrc파일에 plugin을 추가시켜준다.

plugins=(
  git
  zsh-autosuggestions
)

 

* 간혹가다 zsh-autosuggestions에서 단어 및 명령어자체를 자동하는 것이 아니라, 한글자만 추천하는 현상이 발생할 경우 아래와 같은 명령어를 입력하면 된다.

echo ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=\'fg=60\' >> $ZSH_CUSTOM/zsh-autosuggestions_custom.zsh

ref. https://github.com/zsh-users/zsh-autosuggestions/issues/243

 

Incomplete suggestions - shows only first character · Issue #243 · zsh-users/zsh-autosuggestions

zsh-suggestions shows just the first character of the suggestion and not the entire string. For example if a have a subfolder document and I type cd d it shows just the o and not ocument. I tried t...

github.com

 

autojump

이전에 이동한 디렉터리에 쉽게 접근할 수 있게 해주는 플러그인 (예. /test/hello/dalsacoo 와 같은 디렉터리를 j dalsacoo  와 같이 이동 가능)

brew install autojump

아래와 같이 plugin 추가

plugins=(
  git
  zsh-autosuggestions
  autojump
)

 

syntax highlighting

command가 잘못입력되거나, 잘 입력했을 때 색이 변한다. (잘못입력되면 빨간색, 잘 입력했을 때는 녹색)

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

# ~/.zshrc 파일에 추가
echo "source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${HOME}/.zshrc

 


바인드키 (bindkey)

  • MacOS 기본 터미널 bash command-line
    • ⌥ + ← 또는 ⌥ + → : 커서를 왼쪽 단어 또는 오른쪽 단어로
    • ⌘ + ← 또는 ⌘ + → : 커서를 start 또는 end of line 으로
  • zsh 의 경우
    • ESC B 또는 ESC F : 커서를 왼쪽 또는 오른쪽 단어로 이동(불편하기 짝이 없음)
    • ⌃ + a 또는 ⌃ + e : 커서를 start 또는 end of line 으로

아래와 같이 .zshrc 파일에 추가함으로써 zsh에서 MacOS 세팅처럼 사용할 수 있다.

bindkey "[D" backward-word
bindkey "[C" forward-word
bindkey "^[a" beginning-of-line
bindkey "^[e" end-of-line

 


참고

https://drasite.com/blog/Pimp%20my%20terminal

https://bryan.wiki/303

 

반응형

댓글