zsh 환경세팅(m1 terminal)

2022. 1. 5. 15:37기타

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

Homebrew 설치

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

Oh My Zsh 설치

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
  • Oh My Zsh를 설치해야 $ZSH_CUSTOM 환경변수 등록 및 plugin 적용이 가능

 

플러그인 설치 및 적용

Linux

설치

1. zsh-syntax-highlighting 

  • 사용가능한 명령어를 색(초록색, 빨간색)으로 구별
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

2. zsh-autosuggestions

  • 최근 명령어 히스토리에 따라 명령어 미리보기 제공
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

적용 방법

1. .zshrc 파일 편집

vim ~/.zshrc

2. 설치한 플러그인 추가

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

3. 적용

source ~/.zshrc

Mac M1

brew install zsh-syntax-highlighting

brew reinstall zsh-autosuggestions

1. .zshrc 편집

vim ~/.zshrc

2. 설치한 플러그인 추가

source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh

3. 적용

source ~/.zshrc

 

 

꾸미기

테마 설정

1. .zshrc 편집

vim ~/.zshrc

2.ZSH_THEME="agnoster"으로 수정

3. 적용

source ~/.zshrc

글꼴 수정

1. D2 coding 글꼴 다운로드
https://github.com/naver/d2codingfont

 

GitHub - naver/d2codingfont: D2 Coding 글꼴

D2 Coding 글꼴. Contribute to naver/d2codingfont development by creating an account on GitHub.

github.com

2. 서체 관리자 > 추가 >  D2CodingAll 추가

3. 터미널 폰트 적용(iterm2) 

  •  Preference > Profile > Default >Text > Front  > D2Coding 변경

Color

1. Preference > Profile > Default >Colors 

  • Color Presets > Visit Online Gallery 접속

2. 원하는 Color 선택 후 url 복사(Snazzy)

3. 파일 생성

curl -LO https://raw.githubusercontent.com/mbadolato/iTerm2-Color-Schemes/master/schemes/Snazzy.itermcolors
  • curl 없을 시 
brew install curl

4.import 후 적용


hostname 변경

1. zshrc

vim ~/.zshrc

2. 코드 추가

# hostname 제거
prompt_context() {}

# user만 노출
prompt_context() {
	if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
		prompt_segment black default "%(!.%{%F{yellow}%}.)$USER" # 원하는 이모지 같은 걸 넣어도됨
	fi
}

변경 전

변경 후


명령어 줄바꿈으로 시작(agnoster 사용 시)

1. agnoster.zsh-theme 수정

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

2. build_prompt 수정

build_prompt() {
  RETVAL=$?
  prompt_status
  ...
  prompt_hg
  prompt_newline # 해당 라인 추가(순서 중요)
  prompt_end
}

3. prompt_newline function 추가

# build_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=''
}

4. 결과


Status Bar

1. [Preferences] - [Profile] - [Session] - Status bar enabled 설정

Status bar enabled

 

2. Configure 설정

  • 원하는 status bar 추가

결과

 

 

참고

https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md

https://velog.io/@taeha7b/bash-zsh

 

'기타' 카테고리의 다른 글

mac 모니터 방향 인식 오류  (0) 2022.07.08
Git연동(PAT(Personal Access Token), SSH)  (0) 2022.01.06
Ubuntu(20.04) SSH설정  (0) 2021.10.25
Rasberry PI 4 무선인터넷 설정  (0) 2021.10.25
JIRA - Confluence 시작하기  (0) 2021.08.03