iTerm2 사용하기

11 September 2019 — Written by Paul Han
#iterm2#terminal#zsh

iTerm2를 어떻게 설치하고 세팅 하는지 아래를 따라가 봅시다

Install 🍺Homebrew

$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install iterm2

brew cask install iterm2

Install zsh

brew install zsh

Install oh-my-zsh plugin

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

Install PowerLevel9k!

$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

vscode 또는 vi 편집기를 사용하여 ZSH_THEME="powerlevel9k/powerlevel9k theme을 설정 합니다.

Install FontForge

$ brew install fontforge

Install Nerd Fonts! Install Script

Meslo LG M Regular Nerd Font Complete.ttf 폰트를 다운로드 하고 설치 합니다.

Install Neofetch

brew install neofetch

Show wireless in terminal

무선인터넷 감지를 위해서 Airport 유틸리티에 대한 심볼릭 링크를 설정 합니다.

$ sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

Install Dracular Theme

Dracular file을 다운로드 한후에

iTerm2 > Preferences > Profiles > Colors Tab 이동한 다음

우측 하단에 있는 Color Presets에 있는 Drop Down 아이템 항목에서 Import를 선택하시고 다운받은 경로에 있는 Dracula.itermcolors 파일을 선택합니다. 이후 다시 Dracula를 선택하여 설정 해주세요

Import power9k configs

제가 설정한 ./zshrc 파일 소스 입니다.

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

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

# This section is for Powerlevel9k theme. Comment the above 
# line "ZSH_THEME=...." and uncomment all these lines below

ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="nerdfont-complete"
prompt_zsh_battery_level() {
    local percentage1=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
    local percentage=$(echo "${percentage1//\%/}")
    local color='%F{red}'
    local symbol="\uf00d"
    pmset -g ps | grep "discharging" >/dev/null
    if [ $? -eq 0 ]; then
        local charging="false"
    else
        local charging="true"
    fi
    if [ $percentage -le 20 ]; then
        symbol='\uf579'
        color='%F{red}'
    #10%
    elif [ $percentage -gt 19 ] && [ $percentage -le 30 ]; then
        symbol="\uf57a"
        color='%F{red}'
    #20%
    elif [ $percentage -gt 29 ] && [ $percentage -le 40 ]; then
        symbol="\uf57b"
        color='%F{yellow}'
    #35%
    elif [ $percentage -gt 39 ] && [ $percentage -le 50 ]; then
        symbol="\uf57c"
        color='%F{yellow}'
    #45%
    elif [ $percentage -gt 49 ] && [ $percentage -le 60 ]; then
        symbol="\uf57d"
        color='%F{blue}'
    #55%
    elif [ $percentage -gt 59 ] && [ $percentage -le 70 ]; then
        symbol="\uf57e"
        color='%F{blue}'
    #65%
    elif [ $percentage -gt 69 ] && [ $percentage -le 80 ]; then
        symbol="\uf57f"
        color='%F{blue}'
    #75%
    elif [ $percentage -gt 79 ] && [ $percentage -le 90 ]; then
        symbol="\uf580"
        color='%F{blue}'
    #85%
    elif [ $percentage -gt 89 ] && [ $percentage -le 99 ]; then
        symbol="\uf581"
        color='%F{blue}'
    #85%
    elif [ $percentage -gt 98 ]; then
        symbol="\uf578"
        color='%F{green}'
    #100%
    fi
    if [ $charging = "true" ]; then
        color='%F{green}'
        if [ $percentage -gt 98 ]; then symbol='\uf584'; fi
    fi
    echo -n "%{$color%}$symbol"
}
zsh_internet_signal() {
    local color
    local symbol="\uf7ba"
    if ifconfig en0 | grep inactive &> /dev/null; then
      color="%F{red}"
      symbol="\ufaa9"
    else
      color="%F{green}"
      symbol="\ufaa8"
    fi
}
##POWERLEVEL9K_DISABLE_RPROMPT=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_beginning"

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon custom_internet_signal custom_battery_status_joined user dir_writable dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time root_indicator background_jobs time disk_usage ram)
#POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
#POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
#POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="\uF09C"
#POWERLEVEL9K_SUDO_ICON=$'\uF09C' # 
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M}"
#POWERLEVEL9K_VCS_GIT_ICON='\uF408 '
#POWERLEVEL9K_VCS_GIT_GITHUB_ICON='\uF408 '
POWERLEVEL9K_VCS_UNTRACKED_ICON='\u25CF'
POWERLEVEL9K_VCS_UNSTAGED_ICON='\u00b1'
POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON='\u2193'
POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON='\u2191'
POWERLEVEL9K_VCS_COMMIT_ICON="\uf417"
POWERLEVEL9K_CUSTOM_BATTERY_STATUS="prompt_zsh_battery_level"

# End Powerlevel9k configuration

ZSH_DISABLE_COMPFIX=true

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
  iterm2
  macports
  man
  osx
  python
  composer
  zsh-syntax-highlighting
  zsh-autosuggestions
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

alias suroot='sudo -E -s'

# source ~/.bash_profile

if [ -f ~/.bash_profile ]; then 
    . ~/.bash_profile;
fi




test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

복사 & 붙여넣기 해서 예쁜 iTerm을 사용하세요~

그리고 항상 수정된 .zshrc 파일을 실행해 주세요

source ~/.zshrc

유용한 Plugin 설치

Install Autosuggestions

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

Install Syntax Highlighting

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

Plug-In Settings

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

.zshrc 파일을 실행 해주세요

source ~/.zshrc